-2

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>
Tieson T.
  • 20,774
  • 6
  • 77
  • 92
Bellatrix
  • 29
  • 1
  • 8

1 Answers1

0

How did you render the partial view?

Try this:

@Html.Action("Chat")
Sergey Litvinov
  • 7,408
  • 5
  • 46
  • 67