gpt4 book ai didi

asp.net-mvc-3 - Razor View 类型不继承自 'System.Web.WebPages.WebPage'

转载 作者:行者123 更新时间:2023-12-04 20:17:28 32 4
gpt4 key购买 nike

我在配置 asp.net mvc 应用程序时遇到问题:

[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

我想做的步骤:
  • 将 Controller 及其 View 移动到单独的库中,并将 dll 放入 bin 文件夹中。
  • 创建虚拟文件提供程序和虚拟文件以从程序集中获取数据:
    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 中:
    <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>
  • 当用户访问此 Controller 的页面时,它会被正确编译为以下类:
    public class _Page_Currency_Index_cshtml : System.Web.Mvc.WebViewPage<GridModel<CurrencyModel>> {
  • 之后它因这个错误而失败(正如我所看到的 - 他是对的,类型 'ASP._Page_Currency_Index_cshtml' 不是从 'System.Web.WebPages.WebPage' 继承的。)

  • 我该怎么做才能让 HttpApplication 知道该页面应该作为 System.Web.Mvc.WebViewPage 而不是 System.Web.WebPages.WebPage 进行管理?

    我试图将 Views/Web.Config 移动到 bin 文件夹中,但它没有帮助。

    最佳答案

    尝试将此添加到 AppSettingsWeb.Config :

    <add key="webpages:Enabled" value="false" />

    关于asp.net-mvc-3 - Razor View 类型不继承自 'System.Web.WebPages.WebPage',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10460913/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com