Doubt Select MVC . NET

Asked

Viewed 26 times

0

I am making an index, to bring the employee and the classification that he is, but if I do so, it appears to me the id of the classification, and not the name:

 @foreach (var item in Model.Funcionario)
    {
        <tr>
            <td>@item.Nome</td>
            <td>@item.ClassificacaoID</td>
            <td align="right">
                <a  asp-action="Editar" asp-route-id="@item.Id" title="Editar"><i class="fa fa-pencil fa-lg"></i></a>&nbsp;
                <a asp-action="Detalhe" asp-route-id="@item.Id" title="Visualizar"><i class="fa fa-eye fa-lg"></i></a>&nbsp;
                <a  asp-action="Excluir" asp-route-id="@item.Id"title="Excluir"><i class="fa fa-trash-o fa-lg"></i></a>&nbsp;
            </td>
        </tr>
    }

In select it is like this:

     public async Task<IActionResult> Index()
    {
        var model = new IndexViewModel();
        model.Mensagem = "Carregando dados";
        model.Funcionario = await db.Funcionarios.OrderBy(f => f.Nome).ToArrayAsync();
        return View(model); 
    }

How can I bring the employee, and the description of the classification of the same ?

  • 1

    But you are using the item.Classificacaoid, then you will print the ID, you need a property of type Classificacao within the viewmodel or the employee, and then use an item.Classificacao.Descricacao

  • I have, and I do, but it returns me the following error Nullreferenceexception: Object Reference not set to an instance of an Object. Remembering that I did so: <td>@item.Classificacoes.Descricao</td>

  • 1

    Are you using Entity? If yes, gave the include?

  • It worked, thanks rs.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.