I have 20 check boxes and a submit button on my MVC4 razor page. User can select multiple check boxes(or can leave all of them unchecked) and click on the submit button. How can I get the selected check box values (yes/no) to my controller using a jQuery ajax POST .
2 Answers
If you want to include "no" values as well for checkboxes, you might have to do something a little more hand-rolled; by default, serialize will not include checkbox values for ones that aren't checked, which can be seen in the jQuery documentation.
You could always iterate over the checkboxes with something like
$("input[type='checkbox']")
and use a for loop going over each one, including it in your JSON data to post to your server.