Home >Backend Development >C++ >How Can I Effectively Handle Model Binding to a List in ASP.NET MVC 4 During an HttpPost?
Model Binding to a List in MVC 4
Binding an IList to a view in MVC 4 can be a challenge when working with an HttpPost. Consider the following:
ViewModel:
public class MyViewModel { public List<Person> Persons{get;set;} }
View:
@model MyViewModel @for( int i = 0; i < Model.Persons.Count(); ++i) { @Html.HiddenFor(m => m.Persons[i].PersonId) @Html.EditorFor(m => m.Persons[i].FirstName) @Html.EditorFor(m => m.Persons[i].LastName) }
Action:
[HttpPost]public ViewResult(MyViewModel vm) { ... }
Key Considerations:
The above is the detailed content of How Can I Effectively Handle Model Binding to a List in ASP.NET MVC 4 During an HttpPost?. For more information, please follow other related articles on the PHP Chinese website!