Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Grid handling error in MVC

I am using the Kendo UI grid via the MVC Helper object. If an error occurs in the ajax call (ie. web server is not available), the request returns an error code, however the Kendo UI grid does not respond and just continues to act as though there is no data being returned.

@(Html.Kendo().Grid<ProcessInformation>()
              .Name("Grid")
              {Edited for brevity}
              .DataSource(datasource => datasource.Ajax()
                  .Read(read => read.Action("SearchProcesses", "SystemProcess")
                      .Data("searchSerialize"))
                  .PageSize(10)
              ).Name("ResultsGrid").Events(events => events.DataBound("gridOnBound")))

The MVC event is below:

public ActionResult SearchProcesses(
        [DataSourceRequest] DataSourceRequest request, string startDate, string endDate, string status, int dataProcessType)
    {
        try
        {
            //does the search and returns the object
        }
        catch (Exception e)
        {
            this.log.ErrorException("Error Encountered in WebInternal.SearchProcesses()", e);
            var result = new JsonResult
            {
                Data = new { Redirect = "../Error/Unexpected" }, 
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
            return result;
        }
    }

Is there a way to have the Kendo UI grid redirect the page to the error page on a failed call? I know I can do it with an ajax call, but I would rather use the Kendo UI MVC Helper functionality.

Is there a way to do this as a global error handler that will apply to all ajax calls?

like image 548
sevargdcg Avatar asked Aug 22 '13 17:08

sevargdcg


1 Answers

For handling errors with the Kendo UI Grid have a look at this question Kendo: Handling Errors in Ajax Data Requests

You have to add an event to the datasource that will handle the error.

like image 131
asymptoticFault Avatar answered Oct 03 '22 00:10

asymptoticFault