Good afternoon. I am attempting to pass rows/records selected via a checkbox column from my data grid to the MVC controller for further processing. I was not certain if I could use the data request manager object to process the selected records' collection. I have attempted multiple variations of Ajax syntax with no success. Any help would be greatly appreciated.
Thank you!
Doug Riley
|
// Button click event handler
document.getElementById('select').addEventListener('click', function (args) {
var gridObj = document.getElementById('Grid').ej2_instances[0];
var selectedRecords = gridObj.getSelectedRecords();
if (selectedRecords.length !== 0) {
// Ajax post is sent with Grid’s selected records
var ajax = new ej.base.Ajax({
url: '/DataGrid/GetSelectedRecords',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(selectedRecords),
successHandler: function (data) {
console.log('Returned data: ' + JSON.parse(data).result);
}
});
ajax.send();
}
})
[Controller part]
[HttpPost]
// ‘OrderDetails’ class contains definition for all the data that will be received from the client. So this class is used here to access the list of data
public IActionResult GetSelectedRecords([FromBody]List<OrdersDetails> data)
{
return Json(new { result = data });
} |
Sujith,
Thank you! I have downloaded the sample and will be attempting your example shortly. I will get back to you on the result.
Much appreciated!
Doug
Sujith,
How would this solution differ if the grid was set up for paging?
Thank you!
Doug