Can i use List or something?
Scott Hanselman has an excellent tutorial for doing this here.
Just take the right sort of collection. Exactly which sort depends on which version:
MVC1 : public ActionResult DoSomething(int[] input)
MVC2 : public ActionResult DoSomething(IList<int> input)
[ArrayOrListParameterAttribute("ids", ",")]
public ActionResult Index(List<string> ids)
{
}
You need to pass them to your action via adding each integer to your POST or GET querystring like so:
myints=1&myints=4&myints=6
Then in your action you will have the following action
public ActionResult Blah(List<int> myints)
MVC will then populate the list with 1,4, and 6
One thing to be aware of. Your query string CANNOT have brackets in them. Sometimes when the javascript lists are formed your query string will look like this:
myints[]=1&myints[]=4&myints[]=6
This will cause your List to be null (or have a count of zero). The brackets must not be there for MVC to bind your model correctly.
If you are trying to send the list from some interface item (like, a table), you can just set their name attribute in the HTML to: CollectionName[Index] for example:
<input id="IntList_0_" name="IntList[0]" type="text" value="1" />
<input id="IntList_1_" name="IntList[1]" type="text" value="2" />
And
public ActionResult DoSomething(List<int> IntList) {
}
The IntList parameter wil receive a list containing 1 and 2 in that order