I am using the following codes..
Controller:
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);
}
and my view is
@model IEnumerable<Pharman.Models.XYZMaster>
@foreach (var item in Model)
{
@item.XYZComment.Comment
}
I get the following error: The model item passed into the dictionary is of type 'System.Collections.Generic.List 1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[farma.Models.XYZMaster].
pls help... TIA
Type of your ViewModel
is IEnumerable<Pharman.Models.XYZMaster>
but you are passing List<string>
You should change your ViewModel
type to IEnumerable<string>
Then:
@model IEnumerable<string>
@foreach (var comment in Model)
{
@comment
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.