Parser Error for Strongly Typed Master Page in MVC 2

半城伤御伤魂 提交于 2020-01-06 04:54:07

问题


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>" %> :(


回答1:


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>" %>



回答2:


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>



回答3:


Make sure the web.config file in the Views directory is good-to-go. Was missing mine and had this exact error.



来源:https://stackoverflow.com/questions/5952713/parser-error-for-strongly-typed-master-page-in-mvc-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!