MVC 5 - 控制器无法看到我需要的命名空间

时间:2014-10-01 10:37:35

标签: c# namespaces asp.net-mvc-5

我正在重建MVC中的应用程序并创建了一个名为App_Code的文件夹。文件夹内部是一个名为SessionManager.cs的文件。我想在我的控制器中引用它,但它无法看到命名空间,我感到困惑。

我的控制器

using System;
using System.Web.Mvc;
using AMT2012.AmtService;
using AMT2014_Prototype.App_Code;

namespace AMT2014_Prototype.Controllers
{
    public class EnquiryController : Controller
    {
        [HttpGet]
        public ActionResult _EnquiryBreadCrumb()
        {
           var finishedStepNumber = 1;
            if (SessionManager.GetSession(SessionManager.FinishedStepNumber) != null)
            {
                // trackbarEnquirySteps.Position = (int)SessionManager.GetSession(SessionManager.FinishedStepNumber);
                // trackbarEnquirySteps.ClientSideEvents.PositionChanging =
                //"function(s,e){  if (e.currentPosition < e.newPosition) { if (e.newPosition <= " + trackbarEnquirySteps.Position + ") { e.cancel = false; } else { e.cancel = true; } } else { e.cancel = false;  } }";

                finishedStepNumber = Convert.ToInt32(SessionManager.GetSession(SessionManager.FinishedStepNumber)) + 1;
            }
            switch (finishedStepNumber)
            {
                case 1:
                    imgStepStatus.ImageUrl = "~/AMTImages/Step1.png";
                    break;
                case 2:
                    imgStepStatus.ImageUrl = "~/AMTImages/Step2.png";
                    break;
                case 3:
                    imgStepStatus.ImageUrl = "~/AMTImages/Step3.png";
                    break;
            }


            if (SessionManager.GetSession(SessionManager.NewEnquiryType) != null)
            {
                var enqType =
                    (EnquiryTypeDto.EnumEnquiryTypeDto)(SessionManager.GetSession(SessionManager.NewEnquiryType));
                switch (enqType)
                {
                    case EnquiryTypeDto.EnumEnquiryTypeDto.EMail:
                        imgEnqTypeHeader.ImageUrl = "~/AMTImages/Icons/email_add.png";
                        imgEnqTypeHeader.ToolTip = "New Email Enquiry";
                        lblEnquiryTypeHeader.Text = "New Email Enquiry";
                        break;
                    case EnquiryTypeDto.EnumEnquiryTypeDto.Letter:
                        imgEnqTypeHeader.ImageUrl = "~/AMTImages/Icons/page_add.png";
                        imgEnqTypeHeader.ToolTip = "New Letter Enquiry";
                        lblEnquiryTypeHeader.Text = "New Letter Enquiry";
                        break;
                    case EnquiryTypeDto.EnumEnquiryTypeDto.Telephone:
                        imgEnqTypeHeader.ImageUrl = "~/AMTImages/Icons/telephone_add.png";
                        imgEnqTypeHeader.ToolTip = "New Telephone Enquiry";
                        lblEnquiryTypeHeader.Text = "New Telephone Enquiry";
                        break;
                    case EnquiryTypeDto.EnumEnquiryTypeDto.InPerson:
                        imgEnqTypeHeader.ImageUrl = "~/AMTImages/Icons/comments_add.png";
                        imgEnqTypeHeader.ToolTip = "New In Person Enquiry";
                        lblEnquiryTypeHeader.Text = "New In Person Enquiry";
                        break;
                    case EnquiryTypeDto.EnumEnquiryTypeDto.MembersArea:
                        break;
                    case EnquiryTypeDto.EnumEnquiryTypeDto.MembersAdvisoryCentre:
                        imgEnqTypeHeader.ImageUrl = "~/AMTImages/Icons/building_add.png";
                        imgEnqTypeHeader.ToolTip = "New MAC Enquiry";
                        lblEnquiryTypeHeader.Text = "New MAC Enquiry";
                        break;

                }
            }
            else
            {
                imgEnqTypeHeader.ClientVisible = false;
                lblEnquiryTypeHeader.ClientVisible = false;
            }
    }
}

Session Manager.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using AMT2012.AmtService;
using AMT2012.RHS.Exchange.Service;

namespace AMT2014_Prototype.App_Code
{
    public class SessionManager
    {
        #region Email Client session strings
        public static string MailBoxFolder = "MailBoxFolder";
        public static string MailBoxEmail = "MailBoxEmail";
        public static string MailBoxMergedEmailConversationIds = "MailBoxMergedEmailConversationIds";
        public static string MailBoxPreviousEmail = "MailBoxPreviousEmail";
        public static string MailBoxEmailAttachmentUploaded = "MailBoxEmailAttachmentUploaded";
        public static string MailBoxSearchString = "MailBoxSearchString";
        public static string MailBoxSearch = "MailBoxSearch";
        public static string MailBoxExpandedConversationId = "MailBoxExpandedConversationId";
        public static string CacheRefresh = "CacheRefresh";

        #endregion

        public static string LoggedInUser = "LoggedInUser";

        public static string ConfirmationPostCodeSearch = "ConfirmationPostCodeSearch";

        #region ContactSearch

        public static string ContactSearchResults = "ContactSearchResults";
        public static string ContactSearchCriteria = "ContactSearchCriteria";
        public static string PreviousSearchCriteria = "PreviousSearchCriteria";
        public static string AddressSearchResults = "AddressSearchResults";

        #endregion

        #region KnowledgeBaseKeyword

        public static string KnowledgeBaseKeyword = "KnowledgeBaseKeyword";

        #endregion


        #region Table Maintenance session strings

        public static string SelectedTableId = "SelectedTableId";
        public static string SelectedTableToEdit = "SelectedTableToEdit";
        public static string CurrentKeywordRelations = "CurrentKeywordRelations";
        public static string EditTableVisibility = "EditTableVisibility";
        #endregion

        #region User Maintenance

        public static string Departments = "Departments";
        public static string UploadedFileData = "UploadedFileData";
        public static string UploadedFileName = "UploadedFileName";
        public static string IsUserImageChanged = "IsUserImageChanged";
        public static string NewUserEmailAddress = "NewUserEmailAddress";



        public static string EditingUserDto = "EditingUserDto";
        public static string EditUserVisibility = "EditUserVisibility";
        public static string IsThemeChanged = "IsThemeChanged";

        public static string CurrentTheme = "CurrentTheme";

        #endregion

        #region "News Content"

        public static string EditingNewsItem = "EditingNewsItem";
        public static string UploadedNewsImage = "UploadedNewsImage";
        public static string UploadedNewsFileName = "UploadedNewsFileName";
        public static string EditNewsItemVisibility = "EditNewsItemVisibility";
        public static string IsNewsItemImageChanged = "IsNewsItemImageChanged";

        #endregion

        #region "Lock Maintenance"

        public static string SectionLocks = "SectionLocks";
        public static string EmailLocks = "EmailLocks";
        public static string ResponseTextLocks = "ResponseTextLocks";
        #endregion

        #region "Paragraph Maintenance"

        public static string SearchParagraphs = "SearchParagraphs";
        public static string EditingParagraph = "EditingParagraph";
        public static string SearchParagraphText = "SearchParagraphText";
        public static string ParagrahSummaryVisibility = "ParagrahSummaryVisibility";
        public static string SelectedDepartmentIdForKeyword = "SelectedDepartmentIdForKeyword";
        public static string SelectedKeywordId = "SelectedKeywordId";
        public static string SelectedKeyword = "SelectedKeyword";

        public static string InsertingParagraph = "InsertingParagraph";
        public static string LoadParagraphs = "LoadParagraphs";


        public static string ParagraphViewerBtnVisibility = "ParagraphViewerBtnVisibility";
        #endregion

        #region "Hortifacts Maintenance"

        public static string EditingHortifact = "EditingHortifact";
        public static string HortifactSummaryVisibility = "HortifactSummaryVisibility";
        public static string SearchHortifactText = "SearchHortifactText";
        public static string SearchHortifacts = "SearchHortifacts";
        public static string SelectedSubjectIdForTopics = "SelectedSubjectIdForTopics";
        public static string SelectedTopicId = "SelectedTopicId";
        public static string SelectedTopic = "SelectedTopic";

        public static string AddHortifactAttachment = "AddHortifactAttachment";
        public static string LoadHortifacts = "LoadHortifacts";

        #endregion


        #region "Leaflet Maintenance"

        public static string ViewingLeafletId = "ViewingLeafletId";
        public static string ReplacedLeafletData = "ReplacedLeafletData";
        public static string ReplacedLeafletName = "ReplacedLeafletName";
        public static string ReplacedLeafletFileExt = "ReplacedLeafletFileExt";
        public static string IsLeafletReplaced = "IsLeafletReplaced";

        public static string AddedLeafletData = "AddedLeafletData";
        public static string AddedLeafletName = "AddedLeafletName";
        public static string AddedLeafletFileExt = "AddedLeafletFileExt";

        public static string LeafletSearchText = "LeafletSearchText";
        public static string LeafletFilterByDeptId = "LeafletFilterByDeptId";

        public static string SelectedLeafletsToAttach = "SelectedLeafletsToAttach";
        public static string AttachedLeaflets = "AttachedLeaflets";

        public static string UploadBatchLeaflet = "UploadBatchLeaflet";
        public static string LeafletCallbackPanel = "LeafletCallbackPanel";

        public static string Leaflets = "Leaflets";

        #endregion


        #region "Hortifact Attachment"

        public static string ViewingHortifactId = "ViewingHortifactId";
        public static string ViewingHortifactIdUnassociated = "ViewingHortifactIdUnassociated";
        public static string ViewHortifactAttachmentId = "ViewHortifactAttachmentId";
        public static string ViewHortifactAttachmentIdUnassociated = "ViewHortifactAttachmentIdUnassociated";
        #endregion

        #region "Web Links Viewer"

        public static string WebLinks = "WebLinks";
        public static string LoadWebLinks = "LoadWebLinks";

        public static string PlantSelectorLink = "PlantSelectorLink";
        public static string PlantSelectorSearchText = "PlantSelectorSearchText";


        #endregion

        #region "ACE Viewer"

        public static string SelectedACESubjectIdForTopics = "SelectedACESubjectIdForTopics";
        public static string SearchedACEDTO = "SearchedACEDTO";
        public static string ACEWebLink = "ACEWebLink";
        //public static string ACELinksAddedtoList = "ACELinksAddedtoList";
        public static string iFrameHeight = "iFrameHeight";

        #endregion

        #region "Sticky Notes"

        public static string Notes = "Notes";
        public static string StickyNoteIndex = "StickyNoteIndex";

        public static string EnquiryItemId = "EnquiryItemId";

        #endregion


        #region "Allocation"

        public static string AllocatedDepartment = "AllocatedDepartment";
        public static string AllocatedUser = "AllocatedUser";

        #endregion

        #region "KBKComboBox"

        public static string SelectedKBK = "SelectedKBK";
        public static string SelectedChildNodeCategory = "SelectedChildNodeCategory";
        public static string SelectedKBKChildID = "SelectedKBKChildID";
        public static string SelectedChildNodeCategoryValue = "SelectedChildNodeCategoryValue"; // Use on Select button click. Value = ChildID(for leaflet & weblink), text for others

        #endregion

        #region "KBKComboBoxGridLookUp"

        public static string SelectedCategoryValue = "SelectedCategoryValue"; // Use on Select button click. Value = ChildID(for leaflet & weblink), text for others
        public static string SelectedCategory = "SelectedCategory";
        public static string SearchKBK = "SearchKBK"; // Contains the responsetext
        public static string KbkDisplay = "KbkDisplay";
        public static string KbkGridAutoFilterText = "KbkGridAutoFilterText";

        #endregion


        #region "Monitors"

        public static string FirstResolvedEnquiryIdOnTop = "FirstResolvedEnquiryIdOnTop"; // For top most enquiry id in grid monitor to be kept open on page load
        public static string FirstCompletedEnquiryIdOnTop = "FirstCompletedEnquiryIdOnTop"; // For top most enquiry id in grid monitor to be kept open on page load
        public static string FirstLoggedEnquiryIdOnTop = "FirstLoggedEnquiryIdOnTop"; // For top most enquiry id in grid monitor to be kept open on page load



        public static string SentResponses = "SentResponses";
        public static string LoggedEnquiries = "LoggedEnquiries";
        public static string CompletedEnquiries = "CompletedEnquiries";
        public static string SystemCompletedEnquiries = "SystemCompletedEnquiries";

        #endregion

        #region WeblinksHistory

        public static string BackHistoryBucket = "BackHistoryBucket";
        public static string CurrentlyDisplayedWebLink = "CurrentlyDisplayedWebLink";
        public static string ForwardHistoryBucket = "ForwardHistoryBucket";

        #endregion

        #region "System Settings"

        public static string ArchiveSettings = "ArchiveSettings";
        public static string MembersAreaEnqAllocation = "MembersAreaEnqAllocation";
        #endregion

        #region "Enquiry"

        public static string EnquiryPersonId = "EnquiryPersonId";

        public static string NewEnquiryType = "NewEnquiryType";
        public static string NewEnquiryContactType = "NewEnquiryContactType";
        public static string NewEnquiryObject = "NewEnquiryObject";

        public static string CurrentNewSection = "CurrentNewSection";

        public static string EmailIdsOfCurrentEnquirer = "EmailIdsOfCurrentEnquirer";

        public static string EmailIdsForChangeResponseFormat = "EmailIdsForChangeResponseFormat";

        public static string LoadingEnquiryItemId = "LoadingEnquiryItemId";

        public static string LoadingEnquiryNumber = "LoadingEnquiryNumber";
        public static string LoadingEnquiryDetails = "LoadingEnquiryDetails";
        public static string CurrentSavedSection = "CurrentSavedSection";

        public static string SelectedCategoryType = "SelectedCategoryType";

        public static string EnquiryEntryPointUrl = "EnquiryEntryPointUrl";

        public static string ExistingEnqNewSection = "ExistingEnqNewSection";

        #endregion

        #region "Enquiry BreadCrumb"

        public static string FinishedStepNumber = "FinishedStepNumber";
        #endregion


        public static string SelectedSupportTicketId = "SelectedSupportTicketId";

        public static string SelectedSupportTicketRecordVersion = "SelectedSupportTicketRecordVersion";

        public static string LoadedPlantNames = "LoadedPlantNames";

        public static string SelectedSubjectId = "SelectedSubjectId";


        public static UserDto GetCurrentUser()
        {
            return GetSession(LoggedInUser) as UserDto;
        }

        public static object SetSession(string sessionString, object obj)
        {
            HttpContext.Current.Session[sessionString] = obj;
            return obj;
        }

        public static object GetSession(string sessionString)
        {
            if (HttpContext.Current == null)
            {
                return null;
            }
            return HttpContext.Current.Session[sessionString];
        }

        public static void UpdateEmail(EmailDto email)
        {
            var mail = (EmailDto)GetSession(MailBoxEmail);

            mail = email;

            SetSession(MailBoxEmail, mail);
        }

        public static LoginDto Login = new LoginDto
        {
            Username = ConfigurationManager.AppSettings["AMTUser"],
            Password = ConfigurationManager.AppSettings["AMTPassword"]
        };

        public static SoaLicenceDto SoaLicenceDto = new SoaLicenceDto
        {
            CallerId = ConfigurationManager.AppSettings["SoaLicenceCallerId"],
            LicenceKey = ConfigurationManager.AppSettings["SoaLicenceCallerPassword"]
        };

        public static void ClearEnquirySessions(bool clearContactSession)
        {
            // this baby clears down all enquiry related sessions.
            SetSession(MailBoxSearch, null);
            SetSession(MailBoxEmail, null);
            SetSession(MailBoxMergedEmailConversationIds, null);
            SetSession(MailBoxEmailAttachmentUploaded, null);
            SetSession(MailBoxExpandedConversationId, null);
            SetSession(MailBoxFolder, null);
            SetSession(MailBoxSearchString, null);

            if (clearContactSession)
            {
                SetSession(EnquiryPersonId, null);
                SetSession(NewEnquiryContactType, null);
            }
            SetSession(ContactSearchResults, null);


            //            SetSession(EnquiryItemId, null);            
            //            SetSession(NewEnquiryType, null);
            //            SetSession(EnquiryEntryPointUrl, null);
            //            SetSession(FirstCompletedEnquiryIdOnTop, null);
            //            SetSession(FirstLoggedEnquiryIdOnTop, null);
            //            SetSession(FirstResolvedEnquiryIdOnTop, null);
            //            SetSession(NewEnquiryObject, null);

            SetSession(NewEnquiryObject, null);
            SetSession(NewEnquiryType, null);
            SetSession(CurrentNewSection, null);
            SetSession(AllocatedDepartment, null);
            SetSession(AllocatedUser, null);
            SetSession(SelectedLeafletsToAttach, null);
            SetSession(SelectedKBK, null);
            //            SetSession(LoadingEnquiryDetails, null);
            //            SetSession(LoadingEnquiryNumber, null);
            //            SetSession(LoadingEnquiryItemId, null);
            SetSession(FinishedStepNumber, 0);

        }

        public static void ClearSessionsBeforeCreatingNewEnquiry()
        {
            SetSession(EnquiryItemId, null);

            SetSession(FirstCompletedEnquiryIdOnTop, null);
            SetSession(FirstLoggedEnquiryIdOnTop, null);
            SetSession(FirstResolvedEnquiryIdOnTop, null);

            SetSession(NewEnquiryObject, null);
            SetSession(LoadingEnquiryDetails, null);
            SetSession(LoadingEnquiryNumber, null);
            SetSession(LoadingEnquiryItemId, null);
            SetSession(CurrentSavedSection, null);

        }

    }
}

我的问题是在我的控制器中说:

Cannot resolve symbol 'App_Code'

Cannot resolve symbol 'SessionManager'

enter image description here

enter image description here

查看截图,了解它在IDE中的外观。

2 个答案:

答案 0 :(得分:1)

出于某种原因,MVC不喜欢项目中的App_Code文件夹。我用了一个不同的名字,但它确实有效。

答案 1 :(得分:1)

App_Code是ASP.Net中的一个特殊文件夹,它干扰了您的命名空间。使用不同的名称,它将起作用。

请参阅此链接:http://msdn.microsoft.com/en-us/library/vstudio/t990ks23(v=vs.100).aspx