我试图创建一个强类型视图与正在使用Html.RenderPartial呈现的“MVC浏览用户控制”()。我的ascx文件的开头是这样的:

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

每次我得到同样的错误(代类型)。我究竟做错了什么?我在.NET 3.5 ASP.NET MVC 1.0 RTM。

有帮助吗?

解决方案

我得到它的工作。我跟着从 HTTP的说明://www.codewrecks.com/blog/index.php/2009/04/05/could-not-load-type-systemwebmvcviewpage/ 和该诀窍我。我要指出,我也升级到了ASP.NET MVC 2.0 RC为3/17/2010第一。问题依然存在,我还是直到我遵循的页面上的说明。我不知道,如果一个新的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>

我也应该注意到,对于MVC 2.0您需要更新版本号的在config。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top