I need to get the value of Navigation Properties

Asked

Viewed 17 times

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.

1 answer

0

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

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

Browser other questions tagged

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