The view must be inferred from WebViewPage or WebViewPage <TModel>

I am following the Justin Slattery plugin architecture tutorial and trying to adapt it for Razor instead of WebForm Views.

Everything else (controllers, loading the plugin assembly, etc.) seems to be in order. However, I cannot use Razor's built-in views to work properly. When I try to go to "HelloWorld / Index", I get the following error:

The view at '~/Plugins/MyProjectPlugin.dll/MyProjectPlugin.Views.HelloWorld.Index.cshtml' must derive from WebViewPage or WebViewPage<TModel>. 

An exception was System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +262

I can enable full stack trace if necessary.

Can anyone advise what I can do wrong?

+70
asp.net-mvc-3 razor embedded-resource
Nov 14 2018-11-11T00:
source share
7 answers

You can check out the following blog post , which is more geared towards Razor.

But to answer your question, since you are now viewing your views from a non-standard location, the ~/Views/web.config no longer used and allows you to specify the base type for your razor views. Therefore, you may need to add the following at the top of each type of razor:

 @inherits System.Web.Mvc.WebViewPage @model ... 
+154
Nov 14 '11 at 20:19
source share

Note. I had a very similar problem, and I finally had to track that I was the only developer with MVC 4.0.0.0 related in their solution.

Everyone else had 3.0.0.0 properly specified and was built / started without errors.

TL; DR Make sure your links match the rest of your development team.

+6
Jul 23 '13 at 20:09
source share

I had the same problem because I did not commit the package folder containing the razor libraries. Then I added the package, it worked, but after the recovery, it broke. Then I turned off automatic startup during assembly, and now it works fine. In my case, nuget was messing around.

+1
Jan 05 '15 at 23:18
source share

This error just appeared today when updating the old MVC3 project to version 4, and for me the solution was to remove the appliesTo="v2.0.50727" attribute in the <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> .

0
Jun 01 '15 at 13:15
source share

I want to share my pain .. the site worked fine in place, however, when I posted it to the IIS client, it threw this error. All web.config files (root and / Views) go well with a working copy of the site.

One of the views (logon.cshtml) had inconsistent line endings, and I did not click the yes button to fix this on my Windows machine.

By clicking "yes" in the "Unsuitable Line Ends" dialog box and publishing the logon.cshtml view, he fixed it for me.

0
Sep 14 '16 at 10:03
source share

I got this error when I tried to add the MVC stage (in particular, the Views folder) to the web API project. Darin Dimitrov answers :

the ~/Views/web.config no longer used and allows you to specify the base type for razor views

And in the comments on this answer, joelnet said :

I was able to copy the web.config file from ~ / Views to my alternate location to solve my problem with this.

and Paul D'Aust said :

If you are unable to get the solution in the @joelnet comment for work, try cleaning and rebuilding the project.

These tips helped me figure out the solution.

First, I copied Web.config from the Views folder of another project in the same solution to my new Views folder. I renamed the main namespace tag to match the new project, and after receiving the error, I deleted another <add namespace="..." /> , which I do not need. Then I called the assembly (just an ordinary assembly, I did not need to clean and rebuild it), and I was able to load the new view without errors.

0
Feb 03 '17 at 17:38 on
source share

Install Package: Install-Package Microsoft.AspNet.WebPages

-one
Apr 04 '16 at 20:39
source share



All Articles