本文介绍了如何在区域中使用常见的 _ViewStart?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的根"中Views 文件夹,我有一个带有以下代码的 _ViewStart:
In my "root" Views folder, I have a _ViewStart with the following code:
@Code
Layout = "~/Views/Shared/_Layout.vbhtml"
End COde
在我的 Area/Public/Views 文件夹中,我有一个来自根视图文件夹的 _ViewStart 的副本.
In my Area/Public/Views folder, I have a copy of my _ViewStart from the root Views folder.
但是当我运行代码时,我得到这个错误:
But when I run the code, I get this error:
Unable to cast object of type 'ASP._ViewStart_vbhtml' to type 'System.Web.WebPages.StartPage'.
我做错了什么?
我也可以为我的区域使用一个 _ViewStart.vbhtml
吗?
Can I use one _ViewStart.vbhtml
for my areas too?
如何在区域中使用 _ViewStart.vbhtml
?
推荐答案
您需要将 ~ViewsWeb.config
文件(或至少以下配置元素)复制到您的区域视图中网络配置:
You need to copy the ~ViewsWeb.config
file (or at least the following configuration elements) into your Area's View Web.Config:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.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=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
这篇关于如何在区域中使用常见的 _ViewStart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!