Multi-Select Dropdown With Checkbox To Insert Values Into Database In MVC 4

Hello everyone,
 
Here, I am trying to implement past checkbox's checked values to the controller and the database. With respect to this information, you can refer to Multi-Select Dropdown With Checkbox In MVC 4 
  1. /*Inside js file*/  
  2.          jQuery(document).on("change"".chkclass"function () {  
  3.         var id ="";  
  4.          $('input[class="chkclass"]').each(function (e) {  
  5.   
  6.                 if (this.checked) {  
  7.                     id = id + $(this).val()+',';                     
  8.                 }  
  9.             });  
  10.           
  11.          function SaveSelecteItems(id) {  
  12.   
  13.         $.ajax({  
  14.             type: "POST",  
  15.             url: "/YourControllerName/YourAddMethodName/",  
  16.             data: JSON.stringify({  
  17.                 id: id.toString();  
  18.             }),  
  19.             contentType: "application/json; charset=utf-8",  
  20.             dataType: "json",  
  21.             async: false,  
  22.             success: function (result) {  
  23.             alert('Successfully Saved!!!')  
  24.               }  
  25.         });  
  26.   
  27.     }  
  28.         }); 
Then inside controller 
  1. public ActionResult SmartSaveCheckedItems(string id)  
  2.         {  
  3.          var eachId = id.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct();  
  4.            foreach (var item in eachId)  
  5.             {  
  6.              //Save or do your action   
  7.             }  
  8.         }  
Ebook Download
View all
Learn
View all