Reputation: 73
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.List1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[farma.Models.XYZMaster].
pls help... TIA
Upvotes: 1
Views: 15104
Reputation: 101742
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
}
Upvotes: 7