0

When I create a user and he's logged in for the first time I get this error when I try to display(View details) the requests that he created so far(0 request created). Once I rerun the application again with the same user the view works and I get no error. Here's the line that's generates the error: @foreach (var item in Model)`

Here's the view that generates the error:

@model IEnumerable<Mutuelle.Domain.Entities.Demande>

@{
    ViewBag.Title = "DemandesAdherent";
}
@{
    Layout = "~/Views/Shared/_LayoutAdherent.cshtml";
}
<h2>DemandesAdherent</h2>

<p>
    @Html.ActionLink("Creér nouvelle", "AddDemande")
</p>
<table class="table">
    <tr>

        <th>
            @Html.DisplayNameFor(model => model.Date)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.nomBeneficiaire)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Nomrubrique)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.etat)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>

        <td>
            @Html.DisplayFor(modelItem => item.Date)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.nomBeneficiaire)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Nomrubrique)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.etat)
        </td>
        <td>

            @Html.ActionLink("Details", "DetailsDemande", new { id=item.DemandeId }) @*|
            @Html.ActionLink("Delete", "DeleteDemande", new { id=item.DemandeId })*@
        </td>
    </tr>
}

</table>
tereško
  • 58,060
  • 25
  • 98
  • 150
Bellatrix
  • 29
  • 1
  • 8
  • Because `Model` is `null`. Make sure you initialize the collection before you pass the model to the view –  Nov 06 '15 at 03:37
  • Possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) –  Nov 06 '15 at 03:37
  • I know that the Model is null. but why does it run without exception after that. the only time it doen't work is for the first log in. If I close the application and run it again it works perfectly fine: the page contains the titles but no information because the Model is null. – Bellatrix Nov 07 '15 at 22:55

0 Answers0