|
[index.cshtml]
@{
List<object> toolbarItems = new List<object>();
toolbarItems.Add(new { text = "Send Selected ID", tooltipText = "Send Selected ID", id = "sendselectedid" });
}
<ejs-grid id="Grid" dataSource="@ViewBag.datasource" toolbarClick="toolbarClick" toolbar=toolbarItems height="270">
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" type="number" textAlign="Right" width="120"></e-grid-column>
-----
</e-grid-columns>
</ejs-grid>
<script>
function toolbarClick(args) {
if (args.item.id === 'sendselectedid') {
var gridObj = document.getElementById("Grid").ej2_instances[0];
// get the selected records in the Grid
var selectedRecords = gridObj.getSelectedRecords();
// get the selected rows in Grid
var selectedRows = gridObj.getSelectedRows();
// get the OrderID value of selected record
var OrderIDVal = selectedRecords[0]["OrderID"]
var ajax = new ej.base.Ajax({
type: "POST",
url: '/Home/GetClientDeviceDocuments',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ selectedId: OrderIDVal }) // pass the selected id in integer format
});
ajax.send().then(function (result) {
var data = JSON.parse(result);
console.log(data);
});
}
}
</script>
[HomeController.cs]
public IActionResult GetClientDeviceDocuments([FromBody] extradata data) // use the correct dataType to deserialize the data
{
var id = data.selectedId;
// do your action as you want with the selectedId
return Json(BigData.GetAllRecords());
}
public class extradata
{
public int selectedId { get; set; }
}
|