Tuesday, June 16, 2015

Grid Checkbox checked values passing to controller



 $("#btnSubmitRetation").on("click", function (e) {      
        var datatype = [];
      //  console.log($(".row-checkbox").length);
      //  console.log($(".row-checkbox:checked").length);
        $(".row-checkbox").each(function (i) {

            var id = $(this).attr("id");
            var defaultValue = "false";
            if ($(this).is(":checked")) {
                defaultValue = "true";
            }          
            dataSet = {
                "key": id,
                "value": defaultValue
            }
            datatype.push(dataSet);

        });


        $.ajax({
            url: '@Url.Action("SaveRecordsRetention", "RecordsRetention")',          
            type: 'POST',
            data: "jsonOfLog=" + JSON.stringify(datatype),
            dataType: 'text',
            success: function (result) {            
            }
        });

Controller:

 [HttpPost]
        public ActionResult SaveRecordsRetention(string jsonOfLog)
        {
            //  var convertedvalue = Newtonsoft.Json.JsonConvert.DeserializeObject>(data);
            try
            {
                if (jsonOfLog != null)
                {
                    List> values = JsonConvert.DeserializeObject>>(jsonOfLog);

                   


                }