1

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?

1 Answer 1

3
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.