I know this question has been asked many times, but this is different.
I have kendo grdi which i get selected and not selected type, the user have free role to make changes and that works. I did tried exmples like this Example1 ,Example2 and many others.
Now the problem is my json object that am trying to pass to the controller became null, I this is what i have tried below.
Can you please correct me if there's something wrong am doing ?
Javascript
JsonObj : This is what i get when i deselect from grid checkbox
[ { mailID: '10' , roleID: '5' , isMailSelected: 'false' } , {
mailID: '11' , roleID: '5' , isMailSelected: 'false' } , {
mailID: '19' , roleID: '9' , isMailSelected: 'false' } ]
function goToControllerSave() {
var jsonObj = displayFilterResults();
$.ajax({
url: '@Url.Action("Save", "Account")',
type: "POST",
dataType: "json",
traditional: true,
data: { myobj: jsonObj },
success: function (data) {
},
error: function (data) {
}
})
}
$(function () {
$('#Grid1').on('click', '.chkbx', function () {
var checked = $(this).is(':checked');
var grid = $('#Grid1').data().kendoGrid;
var dataItem = grid.dataItem($(this).closest('tr'));
dataItem.set('isSelected', checked);
})
})
//My json obj: this returns results on Alert
function displayFilterResults() {
var items = "[";
var dataSource = $("#Grid1").data("kendoGrid").dataSource;
var filters = dataSource.filter();
var allData = dataSource.data();
var query = new kendo.data.Query(allData);
var filteredData = query.filter(filters).data;
items = items + " { mailID: '" + item.mailID + "' , roleID: '" +
item.roleID + "' , isSelected: '" + item.isSelected + "' } ,";
});
if (items.charAt(items.length - 1) == ',') {
items = items.substr(0, items.length - 1);
}
items = items + "]";
alert(items)
return items;
}
My conntroller
public class myItems
{
public string mailID { set; get; }
public string roleID { set; get; }
public string isSelected { set; get; }
}
[HttpPost]
public ActionResult Save(List<myItems> myobj)
{
--------------
--------------
}