I need to get the value of the Navigation Properties

0

Friends, how do I display an information in my View through a navigation property, type:

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>

In this way the field "AccountsDetailId" displays the Guid saved in the bank. What I need is the "name of the Chart of Accounts". I thought if I used the Navigation property of my ViewModel I could get the information. Like, I thought I'd do something like this:

<td>@Html.DisplayFor(modelItem => item.PlanoDeContas.Nome)</td>

But that simply leaves the field blank.

So how do I get the value of the navigation property? I would like to do this in Controller and then pass the result to View.

    
asked by anonymous 21.10.2018 / 15:10

1 answer

0

As already answered in another similar topic, just generate a query with the Include method type:

public IEnumerable<Orcamento> FindAll()
{
    return DbSet.Include(p > p.PlanoDeContas).Where(c => c.OrcamentoId > 0).ToList();
}
    
22.10.2018 / 10:50