How to handle MVC model binding prefix with same form repeated for each row of a collection?
- 阅读更多 关于 How to handle MVC model binding prefix with same form repeated for each row of a collection?
My main view model has a collection of ChildViewModel. In the view, I loop over the collection and call EditorFor(), like so: @for (int i = 0; i < Model.Children.Count; i++) { @Html.EditorFor(m => m.Child[i]); } The editor template looks like: @model ChildModel @using (Html.BeginForm("EditChild", "MyController")) { @Html.HiddenFor(m => m.ChildId) @Html.TextBoxFor(m => m.ChildName) } This will generate markup where each children is in a separate form, and each such form will have an input control with name like Child[0].ChildName. I use a separate form for each children, as the children will be