I am in the process of upgrading to MVC4. I have followed the instructions at http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806 but in my Razor views and layou
As for me, it was a stupid deployment mistake: Web projects can have more than one web.config. It was working on the developer's machine and not in production, but we were not realising that the deployment script only grabbed the Web.config
file at the root, and it didn't copy the Web.config
file in the Views
folder.
As a variation on a theme, I could have sworn up and down that my Views\Web.config was correct:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
But I in fact needed to reference Version=4.0.0.1
, not Version=4.0.0.0
because of that security update that got pushed out a while back.
I had the same issue when updating to MVC 5 and it was solved by updating the web.config inside the Views folder.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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>
The host -> factoryType was set to version:4.0.0.0 hope this helps anyone.
Right, I've been trying to fix this issue for sometime. I've used all the solutions in the various Stack Overflow topics regarding this and none seemed to be working.
I have just fixed the issue this morning. After you gave fixed the web.config for both the project and the views, making sure all the .dll versions are matching with what you have in the references folder. You will need to unload the project, edit the .csproj, and then update all the .dll versions in that file.
System.Web.Helpers
System.Web.Mvc
System.Web.WebPages
Hope this helps, as I have finally fixed this issue! No more red squiggly lines.
This has also fixed the context menu issue I was having where, I wasn't getting the option to add a controller, view etc.