@(Html.EJ().Grid<MvcApplication66.OrdersView>("FlatGrid") .Datasource(ds => ds.URL("/Home/DataSource/").UpdateURL("/Home/Update").InsertURL("/Home/Insert").Adaptor(AdaptorType.UrlAdaptor)) .AllowPaging() .ToolbarSettings(tool => tool.ShowToolbar().ToolbarItems(tools => { . . . . . })) .EditSettings(edit => edit.AllowEditing().AllowAdding().AllowDeleting().EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template")) .. . . . .. .ClientSideEvents(events => events.ActionFailure("failed")) namespace MvcApplication66.Controllers { public class HomeController : Controller { . . . . . public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm) { . . . . .. } public ActionResult Insert(EditableOrder value) { var obj = OrderRepository.GetAllRecords().Where(ord => ord.OrderID == value.OrderID).SingleOrDefault(); if(obj != null)//Check already exisiting throw new InvalidOperationException("OrderID already existis");//Exception thrown if exisiting OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); } . . . .. } function failed(args) {//after exception from the server, we can alert the client-side using actionFailure //args.error provides the details of exception window.alert("OrderID already existis"); $("#FlatGrid").ejWaitingPopup("hide") |
@(Html.EJ().Grid<MvcApplication66.OrdersView>("FlatGrid") .Datasource(ds => ds.URL("/Home/DataSource/").UpdateURL("/Home/Update").InsertURL("/Home/Insert").Adaptor(AdaptorType.UrlAdaptor)) .AllowPaging() . . . . . . . .ClientSideEvents(events => events.ActionFailure("failed").ActionComplete("complete")) ) <script> function failed(args) { //args.error provides the details of exception //after exception from the server, we can alert the client-side using actionFailure window.alert(($($(args.error.responseText).find('b')[0]).text() + ":" + $(args.error.responseText).find('i').text())); $("#FlatGrid").ejWaitingPopup("hide") } . . . . </script> public ActionResult Insert(EditableOrder value) { var obj = OrderRepository.GetAllRecords().Where(ord => ord.OrderID == value.OrderID).SingleOrDefault(); if(obj != null) throw new InvalidOperationException("OrderID already existis");//Exception thrown OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); |