I missed a little thing while passing a list from view to controller. It displays null in [HttpPost]
method of controller. Anyone please guide that how can I ge
With a foreach
loop, MVC just creates the same inputs over and over again, because it doesn't know that they should be different. Therefore you need to use for
-loops, and use indexes. I don't see any inputs in your form, so I'll just give you an example:
@if (Model != null) {
for (var i = 0; i < Model.Count; i++) {
@Html.TextBoxFor(m => Model[i].SomeProperty)
}
}
Also, if I remember correctly, you need to use an IList
as model:
@model IList<payorder_draft_printing.Models.registration>
To be able to post your (non-editable) texts, you need to add hidden inputs:
@Model[i].account_number
@Html.HiddenFor(m => Model[i].account_number)