5

我與配置asp.net的MVC應用程序中的問題:我想做Razor視圖類型不繼承 'System.Web.WebPages.WebPage'

[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文件夾。
  • 創建虛擬文件提供商和虛擬文件彙編得到的數據:

    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> 
    
  • 當用戶訪問該控制器的頁面是編譯正確地分爲以下類別:

    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進行管理?

我已經試過移動瀏覽/ Web.Config中進入bin文件夾,但它並不能幫助。

回答

4

嘗試Web.Config添加此向AppSettings

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

我一直在尋找這一點。感謝它的工作 – mzain