".. must derive from WebViewPage, or WebViewPage<TModel>" on MonoDevelop & MVC3 (OS X)
Solution 1
If anybody does experience this, it's simply because the web.config file which resides under the "Views" folder has not been updated so one which references the MVC3 Razor components. Duh.
Easiest thing to do is copy one from an existing MVC3 project.
Solution 2
Solution 1.
Add following line on top of your cshtml file.
@inherits System.Web.Mvc.WebViewPage
You must be wondering now thinking that views in ASP.NET MVC templates do not have this line on top of the cshtml file? So let’s see the second solution.
Solution 2.
Add a web.config file and specify the same setting for all the views. This is the minimum required code in this configuration file to get rid of this error message.
<?xml version="1.0"?> <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> <pages pageBaseType="System.Web.Mvc.WebViewPage" ></pages> </system.web.webPages.razor> </configuration>
Actual setting required is pageBaseType="System.Web.Mvc.WebViewPage". Other text is only required to define the tags.
Reference Link: clickHere
Solution 3
For some reason, it is needed that you add @model at the top. I could fix by adding the below statement at the top of the page although I don't pass anything to that page.
@model String
Mr Chris
Updated on July 09, 2022Comments
-
Mr Chris almost 2 years
I'm trying to get an MVC 3 Razor project going with MonoDevelop.
I've created a new ASP.net MVC 2 project using Mono 2.10.9 / MonoDevelop 3.0.4.7, and copied the below DLL's from an existing Windows-based MVC3 project to the "bin" directory of the Mono project:
System.Web.Helpers.dll System.Web.Razor.dll System.Web.WebPages.Deployment.dll System.Web.WebPages.dll System.Web.WebPages.Razor.dll
Have set the project to use Mono / .NET 4. The default Index file has been deleted and replaced with an Index.cshtml file. When I execute the project I get the below error:
The view at '~/Views/Home/Index.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.
What's odd is that I've been through this process before and had MVC 3 pages working. It's only since upgrading Mono (which claims to support Razor...?) that it's now no longer working for me. The projects I've created previously with MVC3 all seem to compile and function in the new Mono version however.
Much appreciated if somebody could point out where I can find some wood amongst these trees :)
-
Darren about 11 years+1 - Was referencing the MVC 4.0. dll and the web config had version 3.0 associated with it.
-
A.R. over 10 yearsWould you care to elaborate on which components are exactly missing ?
-
sandeep talabathula over 9 yearsIn my case - it was this guy in web.config creating problem: <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" /> (it was having 5.0 instead of the correct one 5.1) I am using mvc5.
-
Shavais about 7 yearsI copied the web.config and the entire references section of the .csproj file from a program which is working fine, and I'm still getting this.
-
Shavais about 7 yearsSo strange. I meticuloulsy duplicated all the references from a working program, along with the web.config. The web config has all this stuff in it, and I've confirmed that the versions are all correct, etc. And yet I still had this problem until I put in Solution 1. And then it worked. Somehow, I'm missing something. It must have to do with one of the references. Maybe a local binary is missing or something. But it seems like that would cause more problems than this.
-
Jeremy Murray about 7 yearsThis helped me find my issue - a CI process was renaming web.config files in artifacts to web.example.config so as to not overwrite them on deploy. I was missing the Views/web.config altogether.
-
Teyler Halama over 6 yearsThank you! I just had to move the folder of razor files to the Views folder. Silly mistake, but totally makes sense.
-
willem almost 5 yearsThis was the solution for my scenario. Weird!
-
Manpreet Singh Dhillon over 2 yearswho says copy and paste is a bad programming habit :)