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:
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.
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.
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 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.
I've tried many things to resolve this issue. To name a few:
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.