代码之家  ›  专栏  ›  技术社区  ›  Matt

ASP.NET MVC强类型部分视图,出现无法加载类型错误

  •  17
  • Matt  · 技术社区  · 16 年前

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Collections.IEnumerable<string>>" %>
    

    执行应用程序并加载呈现此控件的页面时,出现以下错误:

     Could not load type 'System.Web.Mvc.ViewUserControl<System.Collections.IEnumerable<string>>'.
    

    所以,我简化了它:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %>
    

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.String>" %>
    

    每次我得到相同的错误(替换类型)。我做错什么了?我使用的是.NET3.5和ASP.NETMVC1.0RTM。

    1 回复  |  直到 16 年前
        1
  •  27
  •   Matt    16 年前

    我成功了。我听从了老师的指示 http://www.codewrecks.com/blog/index.php/2009/04/05/could-not-load-type-systemwebmvcviewpage/ 这对我来说是个好办法。我应该注意到,从2010年3月17日起,我也首先升级到了ASP.NETMVC2.0RC。这个问题一直困扰着我,直到我按照那一页上的说明去做。我不确定一个新的MVC项目现在是否能为您做到这一点。

    如果引用的页面消失,解决方案是向“我的视图”目录添加一个Web.config,并将其放入其中:

    <?xml version="1.0"?>
    <configuration>
      <system.web>
      <httpHandlers>
        <add path="*" verb="*"
          type="System.Web.HttpNotFoundHandler"/>
      </httpHandlers>
    
    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <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>
    

    我还应该注意到,对于mvc2.0,您需要更新配置中的版本。