Visual Studio 2015 Razor View MVC Types not recognized

无人久伴 提交于 2019-11-30 07:54:31

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.

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.

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" />
kleine beertje

I think similar problem was described here - https://stackoverflow.com/q/22832435/3350527. Old version of System.Web.Mvc in use (by VS 2015 opinion).

I've tried many things to resolve this issue. To name a few:

  1. Checking and un-checking Tools->Text Editor->All Languages-> Auto List Members and Parameter information
  2. Restarting Visual Studio
  3. Deleting all sorts of file(s) in various folders:bin, *.sou, %AppLocacalData%\Temp and etc.

Nothing worked.

Then I've went to Control Panel and run Visual Studio setup and clicked 'Repair' button. After process has finished it offered to restart the machine and after that intellisense started to work again in razor views.

Reid

From Chris Zhao on asp.net: You could consider uninstalling VS 2015, and reinstall it again,and check whether "Web Developer tools" is selected [go into Custom during the installation to be sure it is checked.

I did this and it got rid of the red underlines under Viewbag.

I discovered that I needed to bump the version for the assemblies dealing with the config sections to 3.0.0.0 in the Views/Web.config file:

  <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>

They were previously all 2.0.0.0.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!