0

I'm using MVC 4 and i've created a controller with read/write actions and views using EF. I've created a new view (so now i have index, details, edit, delete, create and newview) and the new view has the exact same code as the index but when i try to acess the new view it gives this error:

An exception of type 'System.NullReferenceException' occurred in App_Web_hcu5njnc.dll but was not handled in user code

The code of the view (same has index but without the create edit details links):

@model IEnumerable<GestorSalas.Models.Horario>

@{
    ViewBag.Title = "ProcurarSalas";
}

<h2>Procurar Salas</h2>

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Disciplina.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Sala.Nome)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Dia)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.HoraEntrada)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.HoraSaida)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Disciplina.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Sala.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Dia)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.HoraEntrada)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.HoraSaida)
            </td>
        </tr>
    }

</table>

Can someone help me? Why it gives that error? Those parameters already have data, they are not empty

tereško
  • 56,151
  • 24
  • 92
  • 147
abcdef
  • 33
  • 1
  • 5
  • Show the relevant code (the model and the GET method) –  Jan 31 '16 at 11:37
  • The reason might be either you are not passing model with current type.i.e you need to pass IEnumerable or the properties model.Sala and model.Displina can be null or final chance would be because of model properties that are outside foreach loop – Vinod Kumar Jan 31 '16 at 13:54

0 Answers0