Hi,
I have the following grid:
@(Html.EJ().Grid<MyViewModel>("mygrid")
.Datasource(ds => ds.Json(Model.MyList.ToList()).RemoveURL("Controller/DeleteOperation").Adaptor(AdaptorType.RemoteSaveAdaptor))
.EditSettings(edit => { edit.AllowDeleting().ShowDeleteConfirmDialog(); })
.AllowPaging()
.AllowSorting()
.AllowFiltering()
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.IsResponsive()
.Columns(col =>
{
col.Field(x => x.model.id).Visible(false).IsPrimaryKey(true).Add();
col.HeaderText("Name").TextAlign(Syncfusion.JavaScript.TextAlign.Left).Field(x => x.model.name).AllowSorting(true).Width(50).Add();
col.HeaderText("Description").TextAlign(Syncfusion.JavaScript.TextAlign.Left).Field(x => x.model.desc).AllowSorting(true).Width(50).Add();
col.HeaderText(" ").IsPrimaryKey(false).Commands(command =>
{
command.Type("edit")
.ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties()
{
Text = "Edit",
Click = "onEditClick",
Width = "30"
}).Add();
command.Type(UnboundType.Delete)
.ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties()
{
Text = "Delete",
Width = "40"
}).Add();
}).AllowFiltering(false).Width(20).Add();
}).ClientSideEvents(eve => eve.ActionFailure("FailMessage"))
Then my controller:
[HttpPost]
public ActionResult DeleteOperation(int key)
{
try
{
_service.Delete(key);
}
catch (Exception ex)
{
throw new Exception("Don't do this again");
}
//blah
//blah
//blah
//blah
return Json(mdel, JsonRequestBehavior.AllowGet);
}
and finally my Javascript error handler:
<script type="text/javascript">
function FailMessage(args) {
this.cancelEdit();
var str = args.error.error.responseText;
alert(str);
}
</script>
When I delete the first time the FailMessage is triggered but after dismissing the error message subsequent delete attempts trigger the following error taken from the browser's console:
jquery?v=bXcTrZGqtrcwKAMRnGbw8uWciL3lUOCOt371LT6hr7w1:1 Uncaught TypeError: Cannot read property 'nodeType' of undefined
at attr (jquery?v=bXcTrZGqtrcwKAMRnGbw8uWciL3lUOCOt371LT6hr7w1:1)
at a (jquery?v=bXcTrZGqtrcwKAMRnGbw8uWciL3lUOCOt371LT6hr7w1:1)
at i.fn.init.attr (jquery?v=bXcTrZGqtrcwKAMRnGbw8uWciL3lUOCOt371LT6hr7w1:1)
at Object.selectRows (ej.web.all.min.js:10)
at Object.deleteRow (ej.web.all.min.js:10)
at Object._triggerConfirm (ej.web.all.min.js:10)
at Object.r (jquery?v=bXcTrZGqtrcwKAMRnGbw8uWciL3lUOCOt371LT6hr7w1:1)
at Object._trigger (ej.web.all.min.js:10)
at Object._btnMouseClickEvent (ej.web.all.min.js:10)
at HTMLInputElement.<anonymous> (ej.web.all.min.js:10)
Initially i did not use the "this.cancelEdit();" but i feel i had to because the grid removes the row regardless.
I used the following link as a starting point:
https://www.syncfusion.com/kb/7135/how-to-return-custom-message-from-controller-when-crud-action-fails
Any idea how I can better handle the error messages while preventing the grid from removing the row in case of an error?
Thank you very much.