【问题标题】:The model item passed into the dictionary is of type 'PagedList.PagedList`, but this dictionary requires a model item of type..传入字典的模型项的类型为“PagedList.PagedList”,但此字典需要类型为..的模型项。
【发布时间】:2012-06-27 05:36:20
【问题描述】:

我正在使用 mvc3 开发一个简单的项目。创建了两个模型客户和电话。 在 CustomerController 中,我使用 PagedList 进行分页。我在客户的索引视图上显示了分页。我想在客户索引视图上显示最后 5 条记录呼叫列表。我为 Call 的索引视图创建了部分视图。我按照以下方式在客户索引页面上使用了部分调用视图--

@Html.Partial("IndexCallPartial")

但在选择客户索引页面后显示错误。错误如下-

The model item passed into the dictionary is of type 'PagedList.PagedList`1[graceCRM.Models.Customer]', but this dictionary requires a model item of type 'graceCRM.Models.Call'.

如何解决这个问题?

【问题讨论】:

    标签: asp.net-mvc-3 partial-views pagedlist


    【解决方案1】:

    错误消息很容易解释。您在其中调用Html.Partial 助手的视图被强类型化为PagedList<Customer> 类。默认情况下@Html.Partial("IndexCallPartial") 等价于@Html.Partial("IndexCallPartial", Model)。这意味着它是PagedList<Customer> 的一个实例,它将被传递给您的部分。但是您的部分并不期望这种情况。错误消息告诉您它期望的实例。

    因此,要解决此问题,您需要传递正确的实例:

    @Html.Partial("IndexCallPartial", some_instance_of_the_correct_type_the_partial_expects)
    

    【讨论】:

      猜你喜欢
      • 2013-10-18
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      • 2020-09-08
      • 2015-09-27
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多