[ValidateAntiForgeryToken]
public ActionResult Insert(Order value)
{
db.Orders.Add(value);
db.SaveChanges();
var data = db.Orders.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
public ActionResult Remove(int key)
{
Order order = db.Orders.Find(key);
db.Orders.Remove(order);
db.SaveChanges();
return Json(order, JsonRequestBehavior.AllowGet);
}
@(Html.EJ().Grid<object>("Editing")
.Datasource(ds => ds.URL("/Home/UrlDataSource").Adaptor(AdaptorType.UrlAdaptor).UpdateURL("/Home/Update").InsertURL("/Home/Insert").RemoveURL("/Home/Remove"))
.EditSettings(edit => edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.InlineFormTemplate).InlineFormTemplateID("#template"))
...
})
.AllowPaging()
.Columns(col =>
{
})
.ClientSideEvents(eve => eve.Load("load"))
)
<script type="text/template" id="template">
<b>Order Details</b>
@Html.AntiForgeryToken()
...
</script>
@*@Html.Partial("EditTemplate")*@
<script>
...
var dmAdaptorInsert = function (data, tableName) {
var res = this.adaptor.insert(this, data, tableName);
...
var adaptor = new ej.UrlAdaptor().extend({
...
insert: function (dm, data, tableName) {
var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();
data['__RequestVerificationToken'] = token;
return {
type: "POST",
url: dm.dataSource.insertUrl || dm.dataSource.crudUrl || dm.dataSource.url,
data: {
__RequestVerificationToken: token,
value: data
}
};
}
})
function load(args) {
this.model.dataSource.adaptor = new adaptor();
this.model.dataSource.update = dmAdaptorUpdate;
this.model.dataSource.insert = dmAdaptorInsert;
this.model.dataSource.remove = dmAdaptorRemove;
}
</script> |
Thank you for your response, I downloaded and test your sample, but the bug persist in the sample, now I suspect that is a version bug, I don't have the same assemblies and I manually edited this to match with mine. I attached a video to show you the problem, thank you for your help.
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; //it is not needed since you have set the function to the record instead of passing the value. so please remove this code.
};
deffer.resolveWith(this, [{ record: record, dataManager: this }]);
}, this),
error: function (e) {
deffer.rejectWith(this, [{ error: e, dataManager: this }]);
}
}, res));
return deffer.promise();
} |
[ValidateAntiForgeryToken]
public ActionResult Insert(Order value)
{
db.Orders.Add(value);
db.SaveChanges();
var data = db.Orders.ToList();
var val = data.Last();
return Json(val, JsonRequestBehavior.AllowGet); //pass the added value after the record being added in DB
} |
Thank You, all works fine after remove the suggested lines.