简体   繁体   中英

No intellisense on namespaces in Views Web.config

I have a MVC5 project I am trying to solve some issues with where I am not getting intellisense on the System.Web.MVC components

In the Web.Config in my views folder I have the following;

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Configuration" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="Helpers" />
        <add namespace="Common.Net.Mvc" />
        <add namespace="Common" />
        <add namespace="MvcSiteMapProvider.Web.Html" />
        <add namespace="MvcSiteMapProvider.Web.Html.Models" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

However when I then reference for example Url., ViewBag or Html.ActionLink etc(also if I reference my Common class which is a .resx generated file). I get errors saying they do not existing the current context.

I can compile and run the code successfully and the pages render just fine, it would be nice to eliminate these errors though and get the intellisense I usually get.

I am running VS2017 Community and I have the Razor extension installed and updated. I have intellisense on other projects it just seems to be this one.

Ok, After much searching and wasting of time, this answer here fixed the issue;

The name 'ViewBag' does not exist in the current context - Visual Studio 2015

Here is a run down of the steps I took (the removal and deletion of files may not be required);

  1. Delete the .suo and .csproj.user from the solution having the issues.
  2. Delete the hidden .vs folder form the route of the solution
  3. Delete the temp asp net files from

C:\\Users\\your.name.here\\AppData\\Local\\Temp\\Temporary ASP.NET Files

  1. Delete the files fro here;

C:\\Users\\your.name.here\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache

Note the above alone didn't fix so then I applied the following in conjunction witht he above.

  1. Compared the .csproj version info with that of the project with the issue and ammend (as it was indeed a project carried over form VS 2012) and as per the link above.

csproj图片

  1. Right click the solution -> 'Manage Nuget Packages...' -> Updates -> select all -> apply updates

This rebuilt the nuget references and the intellisense came back. Hopefully one day, somewhere this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM