trendl
trendl

Reputation: 1147

passing arguments to Action methods in ASP.NET MVC

Can anyone advise me how to write an action method that handles data from a form with the following input elements?
<input type="checkbox" name="check[1]" />
<input type="checkbox" name="check[3]" />
The numbers in square brackets are not array indexes but can be IDs e.g. Also, I do not know how many such input fields the form is going to have. Or is there a better of passing such data from a form?

Upvotes: 1

Views: 363

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126547

public ActionResult Foo(IEnumerable<string> check)
{

...then put the ID in the value attribute of the input. You'll get a list of the IDs of the checked inputs.

You can change IEnumerable to IEnumerable or IEnumerable if your IDs happen to be in that format. The MVC framework will convert it for you.

Upvotes: 3

Related Questions