0
Friends, how do I show in my View information through a navigation property, like:
My View:
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>@Html.DisplayNameFor(model => model.Mes)</th>
<th>@Html.DisplayNameFor(model => model.PlanoDeContasId)</th>
<th>@Html.DisplayNameFor(model => model.Valor)</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in (IEnumerable
<PoolAnalysisDfpAccountViewModel>)ViewBag.ListaPagina1) {
<tr>
<td>@Html.DisplayFor(modelItem => item.Mes)</td>
<td>@Html.DisplayFor(modelItem => item.PlanoDeContasId)</td>
<td>@Html.DisplayFor(modelItem => item.Valor)</td>
<td>
//Links para outras áreas da aplicação
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
This way the field "Planodecontasid" is presented the Guid saved in the bank. What I need is to present the "Account Plan name". I thought if I used the navigation property from my Viewmodel I managed to get the information. Like, I thought to do something like this:
<td>@Html.DisplayFor(modelItem => item.PlanoDeContas.Nome)</td>
But it just leaves the field blank.
So, how to get the value of the navigation property? I would like to do this in the Controller and then pass the result to the View.
Possible duplicate of Get value from an entity via navigation property
– Barbetta