When you need to output multiple checkboxes and change certain things based on which ones are checked or unchecked only when the SAVE button is clicked or something then the easiest way to do it is to built Key/Value pairs in jQuery and accessing them in your code as Dictionary values.


I have given all of the checkboxes the same class name and assigned their primary key as the id value.

Now using jQuery loop through all of the elements for that class and built up a dictionary for their ID and ‘checked’ value. Then in this case I am sending those values in an HTTP POST request to an action method called TestOne:

Now in your code simply accept a Dictionary<int, bool> values and now you have access to each checkboxes ‘checked’ property as well as their primary keys:

Leave a comment