There are a lot of examples on how to use the built-in Model-binding capabilities to automatically get a List of items. But they all refer to the Beta-releases of ASP.net MVC. It is also mentioned that there has been a change in this Model Binding but so far I was not able to find a good source on how it now works in the Final Release. And I`m far away of beeing capable to interprete the source code :-)
So would be great if someone could explain me how I would need to prepare a List of values in the View to get it nicely back in an IList of specific objects.
appreciate your help
Maik
From stackoverflow
-
View:
<% using(Html.BeginForm("Retrieve", "Home")) %> { %> <% var counter = 0; %> <% foreach (var app in newApps) { %> <tr> <td><%=Html.CheckBox(String.Format("myAppList[{0}].Id", counter), app.ApplicationId) %></td> <!-- ... --> <td><%=Html.Input(String.Format("myAppList[{0}].SomeProperty1", counter), app.SomeProperty1) %></td> <td><%=Html.Input(String.Format("myAppList[{0}].SomePropertyN", counter), app.SomePropertyN) %></td> <% counter = counter + 1; %> </tr> <% } %> <input type"submit" /> <% } %>Controller:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Retrieve(IList<MyAppObject> myAppList)Maik Koster : Ouch, that was almost to easy. Thanks for your help.Andrey Tkach : I am glad that it heled.
0 comments:
Post a Comment