我正在关注 Justin Slattery 的插件架构教程 并尝试使其适应 Razor,而不是 WebForm 视图.
I'm following Justin Slattery's Plugin Architecture tutorial and trying to adapt it for Razor, instead of WebForm Views.
其他一切(控制器、插件程序集加载等)似乎都没问题.但是,我无法使嵌入的 Razor 视图正常工作.当我尝试浏览到HelloWorld/Index"时,出现以下错误:
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>.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?
推荐答案您可以查看 以下博文 更适合 Razor.
You may checkout the following blog post which is more adapted to Razor.
但是要回答您的问题,由于您现在从非标准位置提供视图,因此不再适用 ~/Views/web.config 文件并允许您指定基础键入您的剃刀视图.因此,您可能需要在每个 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 ...更多推荐
视图必须从 WebViewPage 或 WebViewPage<TModel> 派生.
发布评论