与此问题类似,我正在使用自定义 VirtualPathProvider 来检索嵌入在 dll 中的视图。如果我不@inherits System.Web.Mvc.WebViewPage
发表观点,我会收到此错误:
The view at '~/Views/Home/Index.cshtml' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.
我正在使用从 WebViewPage 继承的自定义 BaseViewPage。在我开始使用这个自定义 VirtualPathProvider 之前,在 web.config 中设置新的基本页面是可行的。现在,如果我尝试在页面上继承我的自定义类,@inherits My.BaseViewPage
我会得到与上面相同的错误。
为了完整起见,我将补充说,如果我从 WebViewPage 继承,页面确实开始编译,但它会引发错误,因为有代码期望视图具有来自 BaseViewPage 的属性。