0

I have a model in a view which is a list:

public PartialViewResult ParcialAlmacenProductoTerminado()
{
    var usuario = Fn.usuario_logeado.traerUsuario();
    ViewBag.usuario = usuario;
    List<op> ops = db.op.Where(x => x.temp != true && x.revisado == true && x.calidad == true && x.calidadRevision == true).ToList();

    return PartialView(ops);
}

And in my view I have this in the model area:

@model List<Produccion.Models.op>

I want to go through it with a foreach or a for (i already tried both) and create and html.textboxfor.

This is the attempt with the for:

@for (int i = 0; i < Model.Count; i++)
{
    @Html.TextBoxFor(x => x.OrdenDeCompra[i], new { @class = "form-control obligatorio " })
}

and the one with the foreach:

@foreach (var p in Model)
{
    @Html.TextBoxFor(x => x.OrdenDeCompras, new { @class = "form-control obligatorio "})
}

none of them work

  • Welcome to SO. What is exactly is not working? What is the actual output and the ouput you expected? – mbuechmann Nov 05 '18 at 18:09
  • it marks me an error in boths ways and i can't create de textboxfor, i'm gonna try add a screenshot – Ricardo Sanchez Santos Nov 05 '18 at 18:37
  • Assuming `OrdenDeCompra` is a property of your `op` model, then its `@Html.TextBoxFor(x => x[i].OrdenDeCompra, new { ... })` (and you cannot use a `foreach` loop - refer [Post an HTML Table to ADO.NET DataTable](https://stackoverflow.com/questions/30094047/post-an-html-table-to-ado-net-datatable/30094943#30094943) –  Nov 05 '18 at 21:24
  • @RicardoSanchezSantos please do not add screenshots of error messages. It is better when you add them as text. The error messages should also be in English. – mbuechmann Nov 06 '18 at 07:13
  • Thanks Stephen, that solve my problem – Ricardo Sanchez Santos Nov 07 '18 at 17:33

0 Answers0