0

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
  • try not to use the name "name" for your columns in the database, use the entity for it aswell, like "Categoryname, Productname" etc. Else it gets very confusing as your application grows Commented Aug 31, 2009 at 11:03

1 Answer 1

1
<%= 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.