I am newbie and getting the error model item passed into directory is of type system.cllection.generic.list but this directory requires system.collection.ienumerable
Please help me to resolve this error. I am pasting my controller and view here
Controller
public ActionResult DisplayComment()
{
var result = Manager.GetUsersWhoHaveConsumedFreeCredit();
JavaScriptSerializer serializer = new JavaScriptSerializer();
var callHistory = serializer.Deserialize<List<CallHistory>>(result);
YelloAdminDbContext db = new YelloAdminDbContext();
if (callHistory != null)
{
foreach (var item in callHistory.ToList())
{
int Id = int.Parse(item.Login);
var note = db.Note.OrderByDescending(i => i.Id).Where(i => i.LoginId == Id).FirstOrDefault();
if (note != null && note.LoginId == Id)
{
var temp = note.Comments.ToList();
return PartialView(temp);
}
else
return Content("No Comments");
}
}
return Content("No Comments");
}
View
@model IEnumerable<MyYello.Admin.Models.CallNote>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Comments)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Comments)
</td>
</tr>
}
</table>
Here you are reuturning List of type Commments:
var temp = note.Comments.ToList();
return PartialView(temp);
while in your view is strongly typed to Model of type IEnumerable<MyYello.Admin.Models.CallNote>
In View you have written, so it conflicts you View is expecting different type while you are passing different type:
@model IEnumerable<MyYello.Admin.Models.CallNote>
you should be returning IEnumerable<MyYello.Admin.Models.CallNote>
from your action or if you need to pass Comments type then change in View :
@model List<MyYello.Admin.Models.Comments>