Usuario
Problema Post en viewmodel con dos tablas.

Pregunta
-
Hola:
Tengo el siguiente viewmodel creado:
public class RecibosRemesaVM { public RecibosRemesaVM() { RecibosPendientes = new List<CobroVM>(); RecibosSeleccionados = new List<CobroVM>(); } public List<CobroVM> RecibosPendientes { get; set; } public List<CobroVM> RecibosSeleccionados { get; set; } }
Al entrar en la vista me visualiza correctamente los recibospendientes, pero cuando hago el post no llegan los resgistros.
El controlador del post es el siguiente:
[HttpPost] [ValidateAntiForgeryToken] public ActionResult Recibos(RecibosRemesaVM model, string accion) { accionesRecibos(ref model, ref accion); List<Cobro> _cobros = new List<Cobro>(); if (model.RecibosPendientes.Count == 0) { model = new RecibosRemesaVM(); List<Cobro> _recibosPendientes = CobrosBL.GetRecibosPendientes(_empresaId); foreach (var item in _recibosPendientes) { CobroVM _cobroVM = new CobroVM(); _cobroVM.ConvertirAVM(item); model.RecibosPendientes.Add(_cobroVM); } } ViewBag.Status = @TempData["resultado"]; ViewBag.TotalGeneral = model.RecibosPendientes.Sum(s => s.Importe).ToString("N2"); ViewBag.TotalGeneralSelec = model.RecibosSeleccionados.Sum(s => s.Importe).ToString("N2"); return View(model); }
Al hacer el post, devuelve 0 registros:
El código de la vista es el siguiente:
@model LaLlaveWeb.ViewModels.RecibosRemesaVM @{ ViewBag.Title = @ViewBag.NombreEmpresa + " - " + "Recibos Pendientes"; } <div class="panel panel-primary"> <div class="panel-heading"> <hr /> <h3 class="box-title"> <b class="text-primary">Recibos</b> </h3> @Html.Partial("_mensaje") <p> </p> </div> <!-- /.box-header --> @using (Html.BeginForm("Recibos", "Remesas", FormMethod.Post)) { @Html.AntiForgeryToken() <div> <h4 class="text-primary">Pendientes <span class="small font-weight-light">(Total: @ViewBag.TotalGeneral)</span></h4> <div class="table-wrapper-scroll-y my-custom-scrollbar table-responsive table-responsive-sm p-0"> <table class="table table-sm "> <thead> <tr> <th> Cliente </th> <th> Factura </th> <th> F. Emisión </th> <th> F. Vto </th> <th> Concepto </th> <th> Importe </th> <th> Anticipo </th> <th> Tipo Cobro </th> <th> F. Cobro </th> <th> Añadir </th> </tr> </thead> <tbody class=""> @foreach (var item in Model.RecibosPendientes) { @Html.HiddenFor(model => item.CobroId) @Html.HiddenFor(model => item.ClienteId) @Html.HiddenFor(model => item.FechaEmision) @Html.HiddenFor(model => item.FechaVencimiento) @Html.HiddenFor(model => item.Concepto) @Html.HiddenFor(model => item.Importe) @Html.HiddenFor(model => item.Anticipo) @Html.HiddenFor(model => item.TipoCobro) @Html.HiddenFor(model => item.FechaCobro) <tr class="detalleAñadir"> <td> @Html.DisplayFor(modelItem => item.ClienteNombre) </td> <td> @Html.DisplayFor(modelItem => item.Factura.NumFactCompleto) </td> <td> @Html.DisplayFor(modelItem => item.FechaEmision) </td> <td> @Html.DisplayFor(modelItem => item.FechaVencimiento) </td> <td> @Html.DisplayFor(modelItem => item.Concepto) </td> <td class="text-right"> @Html.DisplayFor(modelItem => item.Importe) </td> <td class="text-center"> @Html.DisplayFor(modelItem => item.Anticipo) </td> <td> @Html.DisplayFor(modelItem => item.TipoCobro) </td> <td> @Html.DisplayFor(modelItem => item.FechaCobro) </td> <td> @Html.EditorFor(modelItem => item.Seleccionar) <button class="btn btn-success btn-añadir p-0" type="submit" value="añadir" name="Accion" data-toggle="tooltip" data-placement="top" title="Añadir"> <i class="fas fa-2x fa-plus-square"></i> </button> </td> </tr> } </tbody> </table> </div> </div> <hr /> <div class=""> <h4 class="text-primary">Seleccionados <span class="small font-weight-light">(Total: @ViewBag.TotalGeneralSelec)</span></h4> <div class="table-wrapper-scroll-y my-custom-scrollbar table-responsive table-responsive-sm p-0"> <table class="table table-sm "> <thead> <tr> <th> Cliente </th> <th> Factura </th> <th> F. Emisión </th> <th> F. Vto </th> <th> Concepto </th> <th> Importe </th> <th> Anticipo </th> <th> Tipo Cobro </th> <th> F. Cobro </th> <th> Añadir </th> </tr> </thead> <tbody class=""> @foreach (var item in Model.RecibosSeleccionados) { @Html.HiddenFor(model => item.CobroId) @Html.HiddenFor(model => item.ClienteId) @Html.HiddenFor(model => item.FechaEmision) @Html.HiddenFor(model => item.FechaVencimiento) @Html.HiddenFor(model => item.Concepto) @Html.HiddenFor(model => item.Importe) @Html.HiddenFor(model => item.Anticipo) @Html.HiddenFor(model => item.TipoCobro) @Html.HiddenFor(model => item.FechaCobro) <tr> <td> @Html.DisplayFor(modelItem => item.ClienteNombre) </td> <td> @Html.DisplayFor(modelItem => item.Factura.NumFactCompleto) </td> <td> @Html.DisplayFor(modelItem => item.FechaEmision) </td> <td> @Html.DisplayFor(modelItem => item.FechaVencimiento) </td> <td> @Html.DisplayFor(modelItem => item.Concepto) </td> <td class="text-right"> @Html.DisplayFor(modelItem => item.Importe) </td> <td class="text-center"> @Html.DisplayFor(modelItem => item.Anticipo) </td> <td> @Html.DisplayFor(modelItem => item.TipoCobro) </td> <td> @Html.DisplayFor(modelItem => item.FechaCobro) </td> <td> <button class="btn btn-warning btn-quitar p-0" type="submit" value="quitar" name="Accion" data-toggle="tooltip" data-placement="top" title="Quitar"> <i class="fas fa-2x fa-minus-square"></i> </button> </td> </tr> } </tbody> </table> </div> </div> } <hr /> </div>
Si alguien me puede decir porque no me devuelve en el post los registros le estaría agradecido.
Un Saludo y Gracias.