---
title: "Pass checked checkboxes to controller through ajax"  
description: "Pass checked checkboxes to controller through ajax"  
author: "Anonymous User"  
published: 2014-03-26  
updated: 2014-03-26  
canonical: https://www.mindstick.com/forum/1987/pass-checked-checkboxes-to-controller-through-ajax  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Pass checked checkboxes to controller through ajax

I am developing a [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) on [ASP.net MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc).

I have a [html](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) form with some checkboxes say A,B,C,D & E and I am [posting](https://www.mindstick.com/forum/34719/cross-page-posting) the form through ajax to one of the controllers.

I would like to distinctly [identify](https://www.mindstick.com/forum/159425/java-app-crash-arrayindexoutofboundsexception-identify-invalid-index) if each [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) boxes are checked from the [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) and perform some [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) based on the selected [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) value.

I would like to know the best practise to acheive this.

## Replies

### Reply by Pravesh Singh

Hi Ashish,

You can do it in many ways. Here i'm giving a example-

Using a model object

Lets assume, you have a model "CheckBoxValues" in server side with the fields

```
public class CheckBoxValues{    public Boolean A { get; set; }    public Boolean B { get; set; }}
```

On your html page, use the code to get values from the checkboxes on a button click handler-

```
var values= {};var StateOfCheckBoxA = $('#CheckBoxA').is(':checked');values.A= StateOfCheckBoxA  ;var StateOfCheckBoxB = $('#CheckBoxB').is(':checked');values.B= StateOfCheckBoxB;var SubmitURL = YourController/ActionMethod/            $.ajax({                type: "POST",                url: SubmitURL,                data: values,                dataType: 'json',                beforeSend: function () {                },                success: function (result) {                },                error: function (request, status, error) {                },                complete: function () {                }            });
```

Now your actionmethod

```
 public JsonResult Create(CheckBoxValues values) {       Boolean checkboxA=values.A;       Boolean checkboxB=values.B; }
```

Hope this will help you.


---

Original Source: https://www.mindstick.com/forum/1987/pass-checked-checkboxes-to-controller-through-ajax

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
