dimanche 7 janvier 2018

Field won't show in Razor View

I have the following domain defined as classes:

public class Unidade
{
    public int UnidadeId { get; set; }
    public string Apelido { get; set; }
    public string Descricao { get; set; }
}

And:

public class Estrutura
{
    public int Id { get; set; }
    public int ProdutoId { get; set; }
    public virtual Produto Produto { get; set; }
    public int UnidadeId { get; set; }
    public virtual Unidade Unidade { get; set; }
    public int UnidadeCompraId { get; set; }
    public virtual Unidade UnidadeCompra { get; set; }
    ...
} 

Where clearly can be noticed I use twice reference to the Unidade class, first as Unidade and then as UnidadeCompra.

I try to show the property Descricao of the unidade in later, having the following controller:

 public ActionResult Index()
    {
        var estruturas = db.Estruturas
            .Include(e => e.Produto)
            .Include(e => e.Unidade)
            .Include(e => e.UnidadeCompra);

        return View(estruturas);
    }

And in the Razor View:

@foreach (var item in Model) {
<tr>
   ...
    <td>
        @Html.DisplayFor(modelItem => item.Unidade.Descricao)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.UnidadeCompra.Descricao)
    </td>
    ...
</tr>

}

The question is... It won't show up... I get blanks, not what is contained in the field Descricao. What's wrong? How can I make it appears?




Aucun commentaire:

Enregistrer un commentaire