我的ViewUserControl中的强类型类无法正常工作?

时间:2009-12-15 22:29:51

标签: asp.net-mvc renderpartial

我在viewuser控件中收到错误:

无法加载类型'System.Web.Mvc.ViewUserControl'

我的viewpage在RenderPartial调用中传递了MyViewUserControllerUserList类。

所以我在做:

  1. action创建其强类型视图数据,该数据具有属性,该属性是我的userlist.ascx期望的强类型类。
  2. userlist.ascx:

    Inherits="System.Web.Mvc.ViewUserControl<MyViewUserControllerUserList>"
    

    我这样做是否正确?

    更新

    为了确保,我的强类型部分用户控件的代码是:

     public class MyViewUserControllerUserList: ViewUserControl 
    {
    
    }
    

1 个答案:

答案 0 :(得分:1)

您所使用的语法看起来是正确的,但您需要确保命名空间也适用。

Inherits="System.Web.Mvc.ViewUserControl<My.Class.Namespace.ModelClass>"

然后你会像这样传递它

<% Html.RenderPartial("PartialName", InstanceOfModelClass); %>

然后使用Model属性在partial内部访问它。

相关问题