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>
<a asp-action="Detalhe" asp-route-id="@item.Id" title="Visualizar"><i class="fa fa-eye fa-lg"></i></a>
<a asp-action="Excluir" asp-route-id="@item.Id"title="Excluir"><i class="fa fa-trash-o fa-lg"></i></a>
</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 ?
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
– Gustavo Santos
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>
– Mariana
Are you using Entity? If yes, gave the include?
– Gustavo Santos
It worked, thanks rs.
– Mariana