Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 Razor View MVC Types not recognized

syntax error

I installed Visual Studio 2015 and rebooted. The "MVC" types are not recognized in 2015 but are still recognized in 2013. This is my "Views" web.config:

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.0.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" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
like image 908
Justin Avatar asked Jul 23 '15 17:07

Justin


3 Answers

We believe these are occurring because you are currently using MVC 4, and MVC 4 tooling is not included with Visual Studio 2015. Only MVC 5 and MVC 6 tooling is included. If you are in fact using MVC 5 and seeing these issues, please do let us know. You can confirm you are using MVC 4 by opening packages.config and scrolling to the entry for Microsoft.AspNet.Mvc. If the version listed starts with "4", this means you are using MVC 4.

Having said that, we appreciate your feedback and the investment you have made in MVC 4. Based on yours and other customers’ feedback, we are looking into the possibility of making MVC 4 tooling available for Visual Studio 2015. In the meantime, your project will compile and run in Visual Studio 2015 despite the tooling issues. Alternatively, you can keep both Visual Studio 2013 and 2015 installed on your machine side-by-side. That way, you can use Visual Studio 2013 for MVC 4 projects and Visual Studio 2015 for MVC 5 and above projects.

like image 131
Mohit Srivastava Avatar answered Oct 17 '22 19:10

Mohit Srivastava


It didn't work for me. It seems that this issue has several root causes related to web.config.

One another problem was root web.config compilation version mismatch.

<compilation debug="true" targetFramework="4.5.2">

<httpRuntime executionTimeout="600" maxRequestLength="10240" requestValidationMode="2.0" targetFramework="4.5.2" />

If httpruntime version is different from the assembly's this may happen.

like image 20
mohghaderi Avatar answered Oct 17 '22 17:10

mohghaderi


If you upgraded from MVC4 to MVC5: in Views/web.config change

   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

to

   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
like image 1
Jeroen K Avatar answered Oct 17 '22 18:10

Jeroen K