pavan pavan - 1 year ago 84
Ajax Question

ajax code for storing multiple checkbox values to an array and pass to controller

Please share the ajax code for storing multiple checkboxes checked values to an array and pass to controller without submit button in MVC4. Please guide me.
Thanks in advance

Answer Source

User Jquery Ajax to call your controller's method.

Controller Code :

 public class CustomerController : Controller 
  public ActionResult Index() 
   return View();

  public ActionResult UpdateOrder()
  // some code
  return Json(new { success = true, message = "Order updated successfully"    }, JsonRequestBehavior.AllowGet);

Jquery code :

url: '@Url.Action("UpdateOrder")', // to get the right path to controller from TableRoutes of Asp.Net MVC
dataType: "json", //to work with json format
type: "POST", //to do a post request 
contentType: 'application/json; charset=utf-8', //define a contentType of your request
cache: false, //avoid caching results
data: {}, // here you can pass arguments to your request if you need
success: function (data) {
     // data is your result from controller
    if (data.success) { 
error: function (xhr) {

Above code has taken as reference from here :

jQuery to call Action Method in ASP.NET MVC C# by Ajax

Hope this would help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download