2012-06-27 41 views
0

我正在開發一個帶有mvc3的簡單項目。創建了兩個模型Customer &調用。 在CustomerController中,我使用PagedList進行分頁。我在客戶的索引視圖中顯示分頁。我想在客戶索引視圖中顯示最後5條記錄呼叫列表。我爲Call的索引視圖創建了部分視圖。我使用客戶索引頁上的部分查看方式 -傳入字典的模型項目類型爲'PagedList.PagedList`,但該字典需要一個類型的模型項目。

@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'. 

如何解決此問題?

回答

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) 
相關問題