views:

28

answers:

2

I need to gather a list of items associated with another item from my user in a ASP.NET MVC project. I would like to have a controller action like bellow.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(int x, int y, IEnumerable<int> zKeys)
{
    //Do stuff here
}

How can I setup my form to pass data in this way? If data of this particular form can't be provided, what's the next best way to pass this type of information in ASP.NET MVC?

A: 
<form action="/url" method="post">
<input name="x" type="text" value="1" />
<input name="y" type="text" value="1" />

<div>
     <input name="zKeys" value="1" />
     <input name="zKeys" value="2" />
     <input name="zKeys" value="3" />
     <input name="zKeys" value="4" />
     <input name="zKeys" value="5" />
     <input name="zKeys" value="6" />
     <input name="zKeys" value="7" />
</div>

omoto
A: 

Scott Hanselman has an excellent article on how to do this here:

ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries http://www.hanselman.com/blog/...BindingToArraysListsCollectionsDictionaries.aspx

Robert Harvey