Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The view must derive from WebViewPage, or WebViewPage<TModel>

I'm following Justin Slattery's Plugin Architecture tutorial and trying to adapt it for Razor, instead of WebForm Views.

Everything else (controllers, plugin assembly loading, etc) seems to be okay. However, I'm not able to get embedded Razor views to work properly. When I try to browse to the "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>.

The exception is thrown by System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +262

I can include the complete stack trace, if needed.

Can anyone advise as to what I might be doing wrong?

like image 286
Nasir Avatar asked Nov 14 '11 20:11

Nasir


3 Answers

You may checkout the following blog post which is more adapted to Razor.

But to answer your question, since you are now serving your views from a non standard location there is no longer the ~/Views/web.config file that applies and allows you to specify the base type for your razor views. So you might need to add the following on the top of each razor view:

@inherits System.Web.Mvc.WebViewPage
@model ...
like image 77
Darin Dimitrov Avatar answered Oct 31 '22 14:10

Darin Dimitrov


Note: I had an extremely similar issue and had to finally track down that I was the only developer with MVC 4.0.0.0 linked in their solution.

Everyone else had 3.0.0.0 properly referenced and was building/running without error.

TL;DR Make sure that your references are the same as the rest of your development group.

like image 6
nolsen311 Avatar answered Oct 31 '22 14:10

nolsen311


I had a same problem because I did not commit the packages folder which contains the razor libraries. Then I added the package, it worked but upon rebuild it broke. Then I turned off nuget automatic run upon build and now it's working fine. In my case, nuget was messing things up.

like image 1
max Avatar answered Oct 31 '22 14:10

max