I need to send 2 values to the controller, one of the values is fixed and the other is a dynamic value that is fetched from a ViewModel
.
The dynamic value is displayed in a table, and it is an input, of type submit
, which if I click on it, both the fixed and dynamic values try to send them to a controller method, but they do not seem to be arriving. I wanted to know if you could help me send them and that they arrive.
This is my view:
<tbody>
<form action="~/Home/LeerOpcion" method="post">
<label hidden value="entrega" name="seleccion"></label>
@foreach (var item in Model)
{
<tr>
<td><button type="submit" class="btn btn-link" value="@item.NumeroEntrega" name="identi">@item.NumeroEntrega</button></td>
<td>@item.NumeroPedido</td>
<td>@item.NumeroRemito</td>
<td>@item.CantFotos</td>
<td>@item.Fecha</td>
<td>@item.Hora</td>
</tr>
}
</form>
</tbody>
And this is my controller method:
public IActionResult LeerOpcion(string seleccion, string identi)
{
List<PedidoViewModel> listaPedidos;
try
{
identi = CleanString(identi);
if (identi == null || identi == "")
{
return View("Index");
}
switch (seleccion)
{
case "pedido":
listaPedidos = VerPedido(identi);
return View("Pedido", listaPedidos);
case "remito":
listaPedidos = VerRemito(identi);
return View("Pedido", listaPedidos);
case "entrega":
listaPedidos = VerEntrega(identi);
return View("Pedido", listaPedidos);
}
return View();
}
catch (Exception ex)
{
ViewBag.error = ex.Message;
return View("Error");
}
From the view I want to send the value of the label (name="selection", value="delivery") and the input (name="identi", value="@item.NumeroDelivery").
I tried with the form, with the @using(Html.Beginform)
... with a [email protected]("LeerOpcion", "Home", new{seleccion = "entrega", identi = @item.NumeroEntrega})
in the input
/button
Can someone help me please?