Good morning I have the following problem create a model to put in another two models to show their data in a single view if I put
public List<Producto> Productos {get; private set;}
public DetalleEntrega Detalle {get; private set;}
At the time of putting: @Html.DisplayNameFor(model=>.Producto.campo)
tells me which field is not in the context and if you already check which field is in my table products
If I change it to the list, I do not get that error but I do it in the
@foreach(var item in Model.Productos)
I get an error that is not of type GetEnumerator.
public Productos {get; private set;}
public DetalleEntrega Detalle {get; private set;}
The two models within one
public class Mimodelo
{
public List<Producto> Productos { get; set; }
public DetalleEntrega Detalle { get; set; }
}
The action resulted in my controller Products
public ActionResult Entrega(int id)
{
var Productos = db.Productos.Where(d => e.IdEntrega==id).Include(p => p.Compra).Include(p => p.Empresa);
var miModelo = new MiModelo();
miModelo.Productos = Productos.ToList();
miModelo.DetallesEntrega = new DetallesEntrega();
return View(miModelo);
}
View
@model Empresa.Models.Mimodelo
@{
ViewBag.Title = "Entrega";
}
<h2>Entrega</h2>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Productos.ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.Entrega.Purpose)
</th>
<th>
@Html.DisplayNameFor(model => model.Productos.Material)
</th>
<th>
@Html.DisplayNameFor(model => model.Entrega.Embarque)
</th>
<th>
@Html.DisplayNameFor(model => model.Entrega.Compras)
</th>
<th>
@Html.DisplayNameFor(model => model.Productos.Comments)
</th>
<th>
@Html.DisplayNameFor(model => model.Entrega.EmpresaT.Empresa)
</th>
<th></th>
</tr>
@foreach (var item in Model.Productos) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Productos.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Entrega.Purpose)
</td>
<td>
@Html.DisplayFor(modelItem => item.Productos.Material)
</td>
<td>
@Html.DisplayFor(modelItem => item.Entrega.Embarque)
</td>
<td>
@Html.DisplayFor(modelItem => item.Entrega.Compras)
</td>
<td>
@Html.DisplayFor(modelItem => item.Productos.Comments)
</td>
<td>
@Html.DisplayFor(modelItem => item.Entrega.EmpresaT.Empresa)
</td>
<td>
</td>
</tr>
}
</table>