1

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 .

1

2 Answers 2

1

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.

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

Comments

0

In jQuery, serialize() on a form will give you all the values. Then you just set this as the data in your post request.

 var attachment = $('form#yourFormId').serialize();

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.