I am posting a form from the view to the controller using Beginform
method, and passing a list of id's through a hidden field.
But it returns only the last value in the list.
View.cshtml
:
@using(Html.BeginForm("makepayment","home",FormMethod.Post))
{
if (Model != null)
{
for (var i = 0; i < Model.Count; i++)
{
@Html.HiddenFor(m => Model[i].cart.vid)
}
}
@Html.TextBoxFor(m => m[0].payment.cname);
@Html.TextBoxFor(m => m[0].payment.number);
@Html.TextBoxFor(m => m[0].payment.securitycode);
@Html.TextBoxFor(m =>m[0].payment.expdate);
<input type="submit" value="pay" />
}
It only returns the last value. The loop isn't working because I used IEnumerable
, but I don't know how to solve