tags:

views:

25

answers:

1

Hello,

I have a for to update a list of entities it is possible to do something like these

<%using (Html.BeginForm())
  {
%>

<% foreach (var entity in Model)
   {
%>
<p>
    <%= Html.TextBox("Entity.Name", entity.Name) %>
</p>
<% } %>
    <input type="submit" value="Update" />
<% } %>

and then in the action receive a list of entities? or a list of names... I don't want to create a form for each entity with his own button, i want to update all the entities toghether. Wich options i have to do these?

Thanks in advance,

Alfredo

+1  A: 
<%= Html.TextBox("name", entity.Name) %>

public ActionResult foo(string[] name)

or

<%= Html.TextBox("Entity["+index+"].Name", entity.Name) %>

//will create list of entities from form values
public ActionResult foo(IList<Entity> entity)

Process in Asp.Net Mvc terminology is called model binding.

This article might be worth checking out. And another one about binding lists.

Arnis L.