Error Handling
Capture error using dataSource error event
var dataSource = new kendo.data.DataSource({
error: function(e) {
var xhr = e.xhr;
var statusCode = e.status;
var errorThrown = e.errorThrown;
$('#KendoGrid').data("kendoGrid").cancelChanges();
}
});
Capture error in complete event
complete: function (jqXhr, textStatus) {
if (textStatus == "success") {
$('#inventoryItemsDetail').data('kendoGrid').dataSource.read();
$('#inventoryItemsDetail').data('kendoGrid').refresh();
toastr.success('Updated successfully.', 'Consumption Edit');
} else {
toastr.error(jqXhr.responseText, 'Consumption Edit');
$('#inventoryItemsDetail').data('kendoGrid').cancelChanges();
}
}
[HttpPost]
public ContentResult Update(IEnumerable<InventoryItemDto> products)
{
try
{
var updateInventoryItemsCommand = new UpdateInventoryItemsCommand();
foreach (var inventoryItemDto in products)
{
updateInventoryItemsCommand.InventoryItems.Add(inventoryItemDto);
}
_commandBus.Submit(updateInventoryItemsCommand);
return new ContentResult { Content = "[]", ContentType = "application/json", ContentEncoding = Encoding.UTF8 };
}
catch (Exception ex)
{
Response.StatusCode = (int)System.Net.HttpStatusCode.ExpectationFailed;
return new ContentResult { Content = ex.Message, ContentType = "application/json", ContentEncoding = Encoding.UTF8 };
}
}