MVC 2 中强类型母版页的解析器错误

发布于 2024-11-06 09:18:53 字数 2341 浏览 1 评论 0原文

我正在尝试创建一个强类型母版页(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 不是抽象类。

我看到这里提出并解决了类似的问题,但我无法找出解决方案:

Parse Error ViewMasterPage

这是 ~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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无悔心 2024-11-13 09:18:53

Resorts.Services.ViewModels.BaseView 所在的程序集是否也在 MVC 项目本身中引用?

此外,您的导入声明是在使用之后出现的。尝试

<%@ Import Namespace="Resorts.Services.ViewModels" %>
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<Resorts.Services.ViewModels.BaseView>" %>

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

<%@ Import Namespace="Resorts.Services.ViewModels" %>
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<Resorts.Services.ViewModels.BaseView>" %>
菩提树下叶撕阳。 2024-11-13 09:18:53

在您的 web.config 中,在确保程序集实际被项目引用后,尝试将程序集添加到 部分:

<compilation debug="true">
    <assemblies>
        ...
        <add assembly="Resorts.Services.ViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </assemblies>
</compilation>

以及将命名空间添加到命名空间部分:

<pages>
    <namespaces>
        ...
        <add namespace="Resorts.Services.ViewModels"/>
    </namespaces>
</pages>

In your web.config try adding the assembly to the <assemblies> section after ensuring that the assembly is actually referenced by your project:

<compilation debug="true">
    <assemblies>
        ...
        <add assembly="Resorts.Services.ViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </assemblies>
</compilation>

as well as the namespace to the namespaces section:

<pages>
    <namespaces>
        ...
        <add namespace="Resorts.Services.ViewModels"/>
    </namespaces>
</pages>
云胡 2024-11-13 09:18:53

确保 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文