I used the exact same actionResult and generated a View (that is not partial) and the code worked just fine. But when I use a partial view I get the error: Object reference not set to an instance of an object. But the reference is not null, the list that I generated in the controller contains values. Here's the controller:
public ActionResult PartialChat()
{
ChatService chatService = new ChatService();
var list = chatService.GetChats();
List<Chat> listChat = new List<Chat>();
foreach (Chat item in list)
{
if (item.date > (DateTime.Now.AddDays(-1)))
{
listChat.Add(item);
}
}
return View(listChat);
}
Here's he view:
@model IEnumerable<Mutuelle.Domain.Entities.Chat>
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.nom)</th>
<th>@Html.DisplayNameFor(model => model.message)</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.nom)</td>
<td>@Html.DisplayFor(modelItem => item.message)</td>
</tr>
}
</table>