Visual Studio highlights non-existent errors on .cshtml pages using MVC5 and Razor

This question has been asked hundreds of times before, but none of the solutions presented work.

I am creating an MVC5 project in Visual Studio 2013. It works fine. However, on all .cshtml pages in VS, all Razor embedded code is underlined in red, as if it were an error. @model and ViewBag indicate that they do not exist in the current context. Html.ActionLink claims to not contain an ActionLink definition. There are other errors on different objects, and intellisense is broken.

These errors also appear when creating a project. However, oddly enough, we have a private registration on TFS, and for this it is great.

MVC and Razor are installed through NuGet. Nugget tells me that this version of MBC is 5.2.3, and the Razor version is set to 3.2.3.

There is a web.config file in the Views folder, and it looks like this:

  <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.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="MyProjectNamespace" /> </namespaces> </pages> </system.web.webPages.razor> <appSettings> <add key="webpages:Enabled" value="false" /> </appSettings> 

The main web.config files have the following section:

 <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> </dependentAssembly> 

Things I tried:

  • Upgrading System.Web.Mvc.MvcWebRazorHostFactory to 5.2.3 does not resolve the issue.

  • Changing the version of System.Web.Mvc in the main web.config file to 5.2.0 does not fix the problem.

  • Updating the versions defined for the razor inside the Group section to 3.2.3 interrupts the application.

  • Changing the value of web pages: included in true in the web.config file in views, and the main web.config file does not fix the problem.

  • Deleting a .suo file or a folder with cells and objects (in combination with the above) does not fix the problem.

  • Installing the Asp.NET Web Help Library from Nuget does not fix the problem.

  • Adding a system.web section to Views \ web.Config with values ​​for pages and controls with the key for MVC version 5.2.3 does not fix the problem.

What else can I try?

+5
source share
1 answer

Try changing the web.config file in the Views folder to use these versions:

 System.Web.WebPages.Razor, Version=3.0.0.0 System.Web.Mvc, Version=5.2.3.0 

The assembly binding reference indicates that you are using version Mvc 5.2.3, not 5.2.0

I had a similar problem and fixed it. I use the latest versions of NuGet from 5/29/15 and just updated from MVC3.

The Razor NuGet package is Microsoft.AspNet.Razor.3.2.3, but the binary code uses this name: System.Web.WebPages.Razor, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35

Here is my web.config file in the views folder:

 <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <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" /> </namespaces> </pages> </system.web.webPages.razor> <appSettings> <add key="webpages:Enabled" value="false" /> </appSettings> <system.web> <httpHandlers> <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> </httpHandlers> <!-- Enabling request validation in view pages would cause validation to occur after the input has already been processed by the controller. By default MVC performs request validation before a controller processes the input. To change this behavior apply the ValidateInputAttribute to a controller or action. --> <pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <controls> <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> </controls> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="BlockViewHandler"/> <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> </handlers> </system.webServer> </configuration> 
+2
source

All Articles