@{Html.EJ().Grid<Object>("FlatGrid")
.Datasource(ds => ds.URL("/Home/DataSource").CrudURL("/Home/CrudUpdate").RemoveURL("/Home/Remove").Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.ClientSideEvents(eve => { eve.ActionComplete("complete").Load("load"); })
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.InlineFormTemplate).InlineFormTemplateID("#template"); })
………
}).Render();
}
<script id="template" type="text/template">
@Html.AntiForgeryToken()
<table cellspacing="10">
<tr>
<td style="text-align: right;">
Order ID
</td>
<td style="text-align: left">
<input id="OrderID" name="OrderID" value="{{: OrderID}}" disabled="disabled" class="e-field e-disable e-ejinputtext valid" style="text-align: right; width: 116px; height: 28px" />
</td>
..
</table>
</script>
<script type="text/javascript">
var dmAdaptorUpdate = function (keyField, value, tableName) {
var res = this.adaptor.update(this, keyField, value, tableName);
return $.ajax($.extend({
beforeSend: ej.proxy(this._beforeSend, this)
}, res));
}
var dmAdaptorInsert = function (data, tableName) {
var res = this.adaptor.insert(this, data, tableName);
var deffer = $.Deferred();
$.ajax($.extend({
beforeSend: ej.proxy(this._beforeSend, this),
success: ej.proxy(function (record, status, xhr, request) {
record = function () {
if (data.d)
data = data.d;
return data;
};
deffer.resolveWith(this, [{ record: record, dataManager: this }]);
}, this),
error: function (e) {
deffer.rejectWith(this, [{ error: e, dataManager: this }]);
}
}, res));
return deffer.promise();
}
var adaptor = new ej.UrlAdaptor().extend({
update: function (dm, keyField, value, tableName) {
var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();
delete value['__RequestVerificationToken'];
return {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
type: "POST",
dataType:"json",
url: dm.dataSource.updateUrl || dm.dataSource.crudUrl || dm.dataSource.url,
data: {
__RequestVerificationToken: token,
value: value,
action: "update",
},
};
},
insert: function (dm, data, tableName) {
var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();
delete data['__RequestVerificationToken'];
return {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
type: "POST",
url: dm.dataSource.insertUrl || dm.dataSource.crudUrl || dm.dataSource.url,
data: {
__RequestVerificationToken: token,
value: data,
action:"insert"
}
};
}
})
function load(args) {
this.model.dataSource.adaptor = new adaptor();
this.model.dataSource.update = dmAdaptorUpdate;
this.model.dataSource.insert = dmAdaptorInsert;
}
</script>
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult CrudUpdate(Orders value, string action)
{
// do your actions here
return Json(new { order });
}
public ActionResult Remove([FromBody]CRUDModel<Orders> myobject)
{
// do your actions here
return Json(new { order });
} |