This is a migrated thread and some comments may be shown as answers.

Handling errors/redirects in DataSource Read

1 Answer 690 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aleks
Top achievements
Rank 1
Veteran
Aleks asked on 27 Feb 2020, 04:34 AM

When binding to remote data:-

    .DataSource(d => d
        .Ajax()
        .Read(r => r.Action("Index", "Books", new { id = Model.Id }))

If an error occurs when calling the controller method, there is no error message and the grid displays no results, so the user doesn't know what's going on.

I'm aware that I can catch errors in my controller method and do something with the DataSourceRequest, however, the particular case I'm experiencing is when a session has been idle and the authentication has timed out, calling the controller method wants to redirect me to the login page.

Usually this would be OK, however, as it's being called in the AJAX handler by the grid, it just fails silently.

How can I catch the error and display it, or ideally, catch the redirect and navigate to the login page?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 02 Mar 2020, 08:59 AM

Hi Aleks,

In case the response from the server-side of the Kendo UI Grid contains an Error collection and it is not null, the Error event of the DataSource would be triggered:

.DataSource(ds=>ds.Events(ev=>ev.Error("onError")))

It accepts a JavaScript function name. Within the handler, you could redirect to a new page, or show the error to the user. The most common approach for returning the error is via the ModelState. A complete example of handling server-side exceptions could be found here:

https://www.telerik.com/blogs/handling-server-side-validation-errors-in-your-kendo-ui-grid

I hope you find this helpful.

 

Regards,
Tsvetomir
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Grid
Asked by
Aleks
Top achievements
Rank 1
Veteran
Answers by
Tsvetomir
Telerik team
Share this question
or