MVC Razor view Intellisense broken in VS 2013/2015/2017

后端 未结 22 2226
失恋的感觉
失恋的感觉 2020-11-27 16:52

I have an existing project written in VS2010 which when loaded in VS2010 works perfectly.

When I load this same project in VS2013 the MVC Razor views contain lots of

相关标签:
22条回答
  • 2020-11-27 17:37

    For anyone else who might stumble across this I didn't find any of the previous answers to really solve my problem or not pertain to it. Anyways the way that solved this for me and made intellisense work again was to go to my bin folder and delete all the files in there and then clean/rebuild and it was fixed.

    0 讨论(0)
  • 2020-11-27 17:37

    In MVC 5 if you try to add an area by just adding a folder under Areas and sub folders for Controllers, Views, Models, etc. you won't have the *AreaRegistration.cs file that registers the area, or the web.config in views that enable VS to understand the razor elements that you include in your views. The result is that intellisense doesn't work in your view for things like ViewBag. If you have working examples of those files in other areas you can copy them in and update as appropriate - or you can start over with your Area by right clicking on Areas and doing an Add - Area which will create those files for you.

    0 讨论(0)
  • 2020-11-27 17:39

    Update the NuGet Packages using Package Manager console in Tool, Library package Manager..

    In command line.. PM> Update-Package This will update NuGet packages and verify the current version of System.web.MVC and update this version in web.config file under Views folder.

    <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.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="System.Web.Webpages"/>
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    

    Close the solution and Reopen.

    Hope this works !!!

    0 讨论(0)
  • 2020-11-27 17:40

    Try setting the CopyLocal property of the System.Web.Mvc reference to true. Sometimes this helps with Intellisense.

    0 讨论(0)
  • 2020-11-27 17:41

    When I created a new project intellisense worked fine, but for some reason it didn't work in our current project. The only difference I found in the Views/Web.config file was that ours had MVC version 5.2.0.0 and a new project had 5.0.0.0. What worked for us was to change this:

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
         Version=5.0.0.0, Culture=neutral, PublicKeyToken=123JHJF56AD364E35" />
    

    to this:

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
         Version=5.2.0.0, Culture=neutral, PublicKeyToken=123JHJF56AD364E35" />
    
    0 讨论(0)
  • 2020-11-27 17:41

    I eventually had a bunch of other problems on my pc because of a network server crash and ended up reinstalling visual studio.

    This apparently solved the problem ... i have no idea how but it did.

    I wonder if maybe in my case it was simply just a faulty installation rather than the typical problem.

    For that reason I will mark this as the answer but +1 all other replies as they are potentially good answers to this problem.

    I did however find that Microsoft clearly states visual studio 2013 does not support intellisense on lower versions of MVC than 4 so if you are using MVC 3 upgrade your project if you are using a newer version of MVC and nothing else here works try reinstalling visual studio.

    Also worth noting ... MVC is now a nuget package so don't install MVC from the download redist allow VS to figure that out for you.

    0 讨论(0)
提交回复
热议问题