MVC 2 中强类型母版页的解析器错误
我正在尝试创建一个强类型母版页(MVC 2.0)并收到以下错误:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewMasterPage<Resorts.Services.ViewModels.BaseView>'.
这是母版页中的我的代码:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<Resorts.Services.ViewModels.BaseView>" %>
<%@ Import Namespace="Resorts.Services.ViewModels" %>
Resorts.Services.ViewModels.BaseView
位于一个单独的程序集中,并且在母版页。 Resorts.Services.ViewModels.BaseView
不是抽象类。
我看到这里提出并解决了类似的问题,但我无法找出解决方案:
这是 ~Views\Web.Config 文件,我没有以任何方式使用它。不确定我是否需要对此进行任何更改。如果我删除此文件,我的视图将引发解析错误。
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
如果我在 Master 中执行 <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
一切正常,但它不喜欢 < %@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage
:(
I am trying to create a STRONGLY TYPED Master Page (MVC 2.0) and getting following error:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewMasterPage<Resorts.Services.ViewModels.BaseView>'.
Here is my code inside Master Page:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<Resorts.Services.ViewModels.BaseView>" %>
<%@ Import Namespace="Resorts.Services.ViewModels" %>
Resorts.Services.ViewModels.BaseView
is inside a seperate assembly and its referenced in Master Page. Resorts.Services.ViewModels.BaseView
is NOT abstract class.
I saw a similar question was asked and resolved here BUT I couldn't figure out the solution:
Parse Error ViewMasterPage<TModel>
Here is ~Views\Web.Config file which I am not using in any way. Not sure if I need to make any changes inside this. If I delete this file, my Views are throwing parsing errors.
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
If I do <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
in Master everything works fine BUT it doesn't like <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<T>" %>
:(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Resorts.Services.ViewModels.BaseView
所在的程序集是否也在 MVC 项目本身中引用?此外,您的导入声明是在使用之后出现的。尝试
Is the assembly where
Resorts.Services.ViewModels.BaseView
is in, also referenced in the MVC project itself?Also your Import statement comes after the usage. Try
在您的 web.config 中,在确保程序集实际被项目引用后,尝试将程序集添加到
部分:以及将命名空间添加到命名空间部分:
In your web.config try adding the assembly to the
<assemblies>
section after ensuring that the assembly is actually referenced by your project:as well as the namespace to the namespaces section:
确保 Views 目录中的 web.config 文件可用。错过了我的并出现了这个确切的错误。
Make sure the web.config file in the Views directory is good-to-go. Was missing mine and had this exact error.