- Home
- Forum
- ASP.NET MVC
- ASP.NET MVC 5 query for Dialog Box Template.
ASP.NET MVC 5 query for Dialog Box Template.
We have prepared a sample with your requirement “To check an already existing data in the datasource” that can be downloaded from the following location.
Sample: https://www.syncfusion.com/downloads/support/forum/123196/ze/DialogEditTemplate1848795145
In the server-side, while inserting a record we can check whether the data is already existing or not in the dataSource. In our case, OrderID is primary key. So we have used them to check the data duplication. Refer to the code example.
|
@(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") |
To inform the client-side about the server-side failure, we have used the actionFailure event of Grid. Refer to the following Help Document.
https://help.syncfusion.com/api/js/ejgrid#events:actionfailure
In the actionFailure event’s parameter, we can get the following information.
Regards,
Seeni Sakthi Kumar S.
Query: Would it be possible to send an error message from the controller method public ActionResult Insert(EditableOrder value) to the function failed(args)
Yes, we can get the server-side exception/error message in the actionFailure event. The parameter (args.error.responseText) get the error message from the server-side. Refer to the following code example
| @(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); |
We have also modified the sample that can be downloaded from the following location.
Sample: https://www.syncfusion.com/downloads/support/forum/123196/ze/DialogEditTemplate1536783885.zip
Regards,
Seeni Sakthi Kumar S.
- 3 Replies
- 3 Participants
-
HR himanshu ratnakar
- Feb 25, 2016 09:14 AM UTC
- Apr 14, 2016 05:20 AM UTC