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>
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" />
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:
- Checking and un-checking Tools->Text Editor->All Languages-> Auto List Members and Parameter information
- Restarting Visual Studio
- 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.
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.
来源:https://stackoverflow.com/questions/31594763/visual-studio-2015-razor-view-mvc-types-not-recognized