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. if (this.checked) {
  6. id = id + $(this).val()+',';
  7. }
  8. });
  9. function SaveSelecteItems(id) {
  10. $.ajax({
  11. type: "POST",
  12. url: "/YourControllerName/YourAddMethodName/",
  13. data: JSON.stringify({
  14. id: id.toString();
  15. }),
  16. contentType: "application/json; charset=utf-8",
  17. dataType: "json",
  18. async: false,
  19. success: function (result) {
  20. alert('Successfully Saved!!!')
  21. }
  22. });
  23. }
  24. });
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. }