我使用如下代碼..傳遞到字典的模型項的類型爲「System.Collections.Generic.List`1 [System.String]」,但需要輸入「別的東西」
控制器:
public ActionResult Comments(int? Id)
{
var abccomment= db.xyzComments.Include(c=>c.XYZMasters);
var comments = (from x in abccomment
where Id == x.CcId
select x.Comment).Distinct().ToList();
return View(comments);
}
和我的看法是
@model IEnumerable<Pharman.Models.XYZMaster>
@foreach (var item in Model)
{
@item.XYZComment.Comment
}
我得到以下錯誤: 傳遞到字典的模型項的類型爲「System.Collections.Generic.List 1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [farma.Models.XYZMaster]。
請幫助... TIA
這是類似於這個職位: - http://stackoverflow.com/questions/4813307/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary-req – sankoobaba