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 layouts I have errors like
I also have errors like:
When I hover over @Html I can see it is of type System.Web.WebPages.Html.HtmlHelper not System.Web.Mvc.HtmlHelper
Not really sure what other information is pertinent but this is where I am:
Any pointers appreciated.
Edit: All references and files in web.config upgraded to:
Edit(2): In my /views/web.config (or /views/shared/web.config if I try @Paul 's solution below) in the element, I have my own base type which inherits from System.Web.Mvc.WebViewPage , the references in the containing library have been updated to MVC4 and go to definition takes me to the MVC4 dll.
Has anything changed in this area on the new release? I couldn't see anything pertinent in the release notes.
I ran into this issue with a Web Application - my .cshtml
files got stuck on the System.Web.WebPages.WebViewPage
base class when I needed the System.Web.Mvc.WebViewPage
.
First, ensure your ~/Views/web.config file has the correct pageBaseType
. In my case, I set to System.Web.Mvc.WebViewPage
.
<configuration> <system.web.webPages.razor> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <!-- ... --> </pages> </system.web.webPages.razor> </configuration>
Then, importantly, some people have found this is key if the above is already good:
.user
file that Visual Studio generated next to the project. For VS2015, the .user
and .sln
files have moved to the .vs
hidden folder that is created next to the .sln
file. However, from comments below, the error messages imply to me that the tooling is using the wrong version of MVC entirely, and deleting this folder does not fix the issue. To my knowledge, there is not a known solution.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With