MVC 4 IntelliSense is not working in Razor in Visu

2019-05-09 05:58发布

问题:

I am using Visual Studio 2010 with ASP.NET MVC4 and the IntelliSense for Razor syntax is not working for me in the views for the application.

What can I do?

回答1:

Also Quoting from

http://sebnilsson.com/1091244048/making-mvc-3-razor-intellisense-work-after-installing-mvc-4-beta/

After installing the MVC 4 Beta the IntelliSense breaks for Razor-views in MVC 3-applications in Visual Studio 2010. This is stated in the release-notes, but nobody usually reads those.

This time the solution to the problem are actually listed in those release-notes. You need to the explicitly state the version-numbers of the references in your web.config.

Add a new appSettings-entry for explicitly stating the version of WebPages to use:

 <appSettings>
     <add key="webpages:Version" value="1.0.0.0"/>
     <!-- ... --> 
 </appSettings>

Then you have to edit your .csproj-file, where you need to find your references to System.Web.WebPages and System.Web.Helpers and makes sure they have the explicit version-numbers like this:

eg:

<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>  

<Reference Include="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

--

Hopefully this will be resolved in the final version of MVC 4 or maybe the case is that the references to versions in Razor v1 were just too loose in MVC 3-projects.

Also a similar question MVC 3 Visual Studio 2010 Razor Model intellisense not working

Also you may need to install VS 2010 SP1 .

Edit:

Also see Required updates on this page
http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253815



回答2:

The problem for me came that in Views\web.config i was referencing an older version of mvc. (I migrated my project from V3 from V4) I updated the version and restarted and i have intellisense now