2016-02-28 53 views
0

我在模型NewsDetail中有一個視圖,我剛剛編輯了News Index View上的所有數據,並希望通過單擊它獲取詳細信息。但每當我點擊它,我得到這個錯誤The model item passed into the dictionary is of type 'CricketTest2.Models.NewsDetail', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable 1[CricketTest2.Models.NewsDetail]'.。我已經盡力解決它。請幫我解決他的問題。謝謝 這裏是我的代碼片段。傳入字典的模型項目類型爲'CricketTest2.Models.NewsDetail',

News Controller + NewsDetail Model

News Index and News Details View

回答

0

從控制器要發送的NewsDetail單個實體,但鑑於您正在使用的NewsDetailIEnumerable接收它。在詳細信息頁面,而不是@model IEnumerable <CricketTest2.Models.NewsDetail>

+0

添加@model CricketTest2.Models.NewsDetail讓我試試@Mahbubur –

+0

它給錯誤... 類型參數的方法「System.Web.Mvc.Html.DisplayExtensions.DisplayFor 中(系統。 Web.Mvc.HtmlHelper ,System.Linq.Expressions.Expression >)'不能根據用法推斷。嘗試明確指定類型參數 –

+0

通過刪除foreach循環解決了Brother問題 –

相關問題