Omu
Omu

Reputation: 71288

how to get an collection of ids int[] in post action (selected checkboxes)

I need to get in an action method the values from the selected checkboxes on a form how would you do that ? (or probably get them all and see who was selected)

public ActionResult (int[] ids)

...

<input type="checkbox" value = "1" />
<input type="checkbox" value = "2" />
<input type="checkbox" value = "3" />
<input type="checkbox" value = "4" />

<%=Html.Submit(); %>

Upvotes: 0

Views: 132

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

You could try giving the checkboxes a name (ids):

<input type="checkbox" name="ids" value="1" />
<input type="checkbox" name="ids" value="2" />
<input type="checkbox" name="ids" value="3" />
<input type="checkbox" name="ids" value="4" />

Should work with:

public ActionResult Index(int[] ids) { ... }

Upvotes: 3

Related Questions