的Razor视图类型不从'System.Web.WebPages.WebPage'继承 [英] Razor view Type does not inherit from 'System.Web.WebPages.WebPage'
问题描述
我有配置asp.net MVC应用程序中的一个问题:
I have a problem with configuring asp.net mvc application:
[HttpException (0x80004005): Type 'ASP._Page_Currency_Index_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.]
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +11454171
System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(String virtualPath) +347
System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(String virtualPath) +239
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +57
System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +407
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
这是我想要做的步骤:
- 将控制器,其观点为独立的库,并把DLL注入bin文件夹。
-
创建虚拟文件提供商和虚拟文件,以获得从汇编的数据:
- Move controllers with its views into separate library and put dll into bin folder.
Create virtual file provider and virtual file to get data from assembly:
public override Stream Open()
{
var resourceName = this.path;
var asmName = this.assembly.GetName().Name;
var manifestName = asmName + ".Views" + resourceName.Trim('~').Replace("/", ".");
var resourceStream = this.assembly.GetManifestResourceStream(manifestName);
return resourceStream;
}
添加此行到web.config中:
Add this lines into web.config:
<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>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web.webPages.razor>
当用户访问这个控制器的页面被正确编译成以下类:
When user access this controller's page it is compiled correctly into the following class:
public class _Page_Currency_Index_cshtml : System.Web.Mvc.WebViewPage<GridModel<CurrencyModel>> {
之后,它失败,出现此错误(和我所看到的 - 他是对的,输入'ASP._Page_Currency_Index_cshtml不从'System.Web.WebPages.WebPage'继承)
And after that it fails with this error (and as I can see - he is right, Type 'ASP._Page_Currency_Index_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.)
我应该怎么做才能让HttpApplication的知道,这个页面应该System.Web.Mvc.WebViewPage而不是System.Web.WebPages.WebPage进行管理?
What should I do to let HttpApplication know that this page should be managed as System.Web.Mvc.WebViewPage instead of System.Web.WebPages.WebPage?
我试图移动浏览/ Web.Config中进入bin文件夹,但它并不能帮助。
I have tried to move Views/Web.Config into bin folder, but it does not help.
推荐答案
尝试 Web.Config中添加这个到
:的AppSettings
Try adding this to the AppSettings
in Web.Config
:
<add key="webpages:Enabled" value="false" />
这篇关于的Razor视图类型不从'System.Web.WebPages.WebPage'继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!