We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to display custom error message on AJAX action failture

Thread ID:

Created:

Updated:

Platform:

Replies:

123776 Apr 20,2016 10:33 AM Apr 21,2016 06:39 AM ASP.NET MVC 1
loading
Tags: Grid
Eric Outley
Asked On April 20, 2016 10:33 AM

I.m trying to display an error message after an update error on the grid.  I'm using the RemoteSaveAdaptor and found some information on the forum on how to do this (https://www.syncfusion.com/kb/5170/how-to-display-custom-error-message-on-ajax-action-failture).  I set the event ActionFailure on the grid, but having a few issues.

To test out everything, I just throw an error (throw new Exception("TEST");) in the controller and the event was fired, but I cannot see any why to get the error message from the event.  If I use the responseText, I get the html from the error page and the statusText says "Internal Server Error".  Is there any way to get the text from the error that was thrown.

Secondly, it seems like the ajax call never completes.  The spinner is still shown and now of the button on the grid is clickable.  

The java script for the function is as follows:

    function grid_ShowFailure(args) {
        alert(args.error.responseText);
    }

Thanks


Jayaprakash Kamaraj [Syncfusion]
Replied On April 21, 2016 06:39 AM

Hi Eric,

Thanks for contacting Syncfusion support.

We are able to get the text from the error that was thrown using ActionFailure event. This event triggers for every grid action server failure event.

We were able to face the issue with waiting popup shown and CRUD operations not reverted when action fails at server side. So, we have logged the requirement as an issue and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates. 

https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents 

As of now, use the below workaround in order to handle this issue. In this workaround, we have used cancelEdit method to stop editing/adding. If waiting popup is displayed in your sample while any server sider action gets failed, we can hide waiting popup manually using hide method of ejWaitingPopUp. Please refer to the following code example, screenshot, help documents and sample.


@(Html.EJ().Grid<object>("FlatGrid")

         .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).UpdateURL("/Grid/Update").InsertURL("/Grid/Insert").RemoveURL("/Grid/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor))

        .AllowSorting()

        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

            .ToolbarSettings(toolbar =>

            {

                toolbar.ShowToolbar().ToolbarItems(items =>

                {

                    items.AddTool(ToolBarItems.Add);

                    items.AddTool(ToolBarItems.Edit);

                    items.AddTool(ToolBarItems.Delete);

                    items.AddTool(ToolBarItems.Update);

                    items.AddTool(ToolBarItems.Cancel);

                });

            })

        .AllowPaging()

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("number", true)).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true)).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(80).EditType(EditingType.Numeric).Format("{0:C}").Add();

            col.Field("ShipCity").HeaderText("ShipCity").Width(150).Add();

        })

        .ClientSideEvents(eve => { eve.ActionFailure("Failure"); })  

)


<script type="text/javascript">

    function Failure(args) {

        var popupObj = $("#FlatGrid").data("ejWaitingPopup");

        popupObj.hide();

        this.cancelEdit();

        var str = "";

        str = $(args.error.responseText).find('i').text();

        alert(str);

    }
</script>
GridController.cs

public ActionResult Update(EditableOrder value)

        {

            throw new Exception("TEST");

            OrderRepository.Update(value);

            var data = OrderRepository.GetAllRecords();

            return Json(data, JsonRequestBehavior.AllowGet);
        }






Help document for actionFailure: http://help.syncfusion.com/js/api/ejgrid#events:actionfailure

Help document for cancelEdit: http://help.syncfusion.com/js/api/ejgrid#methods:canceledit

Help document for waitingpopoup: http://help.syncfusion.com/js/api/ejwaitingpopup#methods:hide

Sample: http://www.syncfusion.com/downloads/support/forum/123776/ze/Sample118221-376676842


Regards,

Jayaprakash K.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;