Handling errors/redirects in DataSource Read

2 posts, 0 answers
  1. Aleks
    Aleks avatar
    23 posts
    Member since:
    Nov 2018

    Posted 26 Feb 2020 Link to this post

    When binding to remote data:-

        .DataSource(d => d
            .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?




  2. Tsvetomir
    Tsvetomir avatar
    796 posts

    Posted 02 Mar 2020 Link to this post

    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:


    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:


    I hope you find this helpful.


    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.
Back to Top