Getting multiple checkboxes from FormCollection element
Posted
by FreshCode
on Stack Overflow
See other posts from Stack Overflow
or by FreshCode
Published on 2010-04-11T16:34:49Z
Indexed on
2010/04/11
16:43 UTC
Read the original article
Hit count: 663
Given multiple HTML checkboxes:
<input type="checkbox" name="catIDs" value="1" />
<input type="checkbox" name="catIDs" value="2" />
...
<input type="checkbox" name="catIDs" value="100" />
How do I retrive an array of integers from a FormCollection in an action:
public ActionResult Edit(FormCollection form)
{
int [] catIDs = (IEnumerable<int>)form["catIDs"]; // ???
// alternatively:
foreach (int catID in form["catIDs"] as *SOME CAST*)
{
// ...
}
return View();
}
Note: I read the related questions and I don't want to change my action parameters, eg. Edit(int [] catIDs)
.
© Stack Overflow or respective owner