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
- /*Inside js file*/
- jQuery(document).on("change", ".chkclass", function () {
- var id ="";
- $('input[class="chkclass"]').each(function (e) {
- if (this.checked) {
- id = id + $(this).val()+',';
- }
- });
- function SaveSelecteItems(id) {
- $.ajax({
- type: "POST",
- url: "/YourControllerName/YourAddMethodName/",
- data: JSON.stringify({
- id: id.toString();
- }),
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- async: false,
- success: function (result) {
- alert('Successfully Saved!!!')
- }
- });
- }
- });
- public ActionResult SmartSaveCheckedItems(string id)
- {
- var eachId = id.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Distinct();
- foreach (var item in eachId)
- {
- //Save or do your action
- }
- }

Join the conversation! Your thoughts help the community grow.