Search code examples
asp.net-mvcasp.net-mvc-controller

How to gather arbitrary length list data in ASP.NET MVC


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?


Solution

  • 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