|
[Index.cshtml]
@{
List<object> commands = new List<object>();
commands.Add(new { buttonOption = new { content="Details", iconCss = "e-icons e-details", cssClass = "e-flat e-details" } });
commands.Add(new { type = "Edit", buttonOption = new { iconCss = "e-icons e-edit", cssClass = "e-flat" } });
commands.Add(new { type = "Delete", buttonOption = new { iconCss = "e-icons e-delete", cssClass = "e-flat" } });
commands.Add(new { type = "Save", buttonOption = new { iconCss = "e-icons e-update", cssClass = "e-flat" } });
commands.Add(new { type = "Cancel", buttonOption = new { iconCss = "e-icons e-cancel-icon", cssClass = "e-flat" } });
}
<ejs-grid id="Grid" load="onLoad" allowPaging="true" allowpaging="true" commandClick="commandClick" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel", "Search"})">
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editsettings>
<e-grid-pagesettings pageSize="5"></e-grid-pagesettings>
<e-data-manager url="/Index?handler=DataSource" insertUrl="/Index?handler=Insert" removeUrl="/Index?handler=Delete" updateUrl="/Index?handler=Update" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
<e-grid-column headerText="Manage Records" width="150" commands="commands"></e-grid-column>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
<e-grid-column field="OrderDate" headerText="Order Date" customFormat="@(new { type ="dateTime", format="MM/dd/yyyy hh:mm:ss a" })" width="170"></e-grid-column>
<e-grid-column field="CustomerName" headerText="CustomerName" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="City" headerText="City" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function commandClick(args) {
if (args.target.innerText == "DETAILS") {
// here we are making an ajax call to server
var ajax = new ej.base.Ajax({
url: "/Index?handler=NewScorecard",
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify({ value: args.rowData })
});
ajax.beforeSend = function (xhr) {
ajax.httpRequest.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
}
ajax.send();
ajax.onSuccess = function (data) {
// on the success event we are showing the data returned from server
alert(data);
};
}
}
</script> |
|
[Index.cshtml.cs]
public JsonResult OnPostNewScorecard([FromBody] CRUDModel<OrdersDetails> value)
{
return new JsonResult(value.Value);
} |