Search code examples
asp.net-mvc-2telerik-mvc

Issue with Telerik MVC grid using AJAX binding and the MVC Authorize attribute


I am using the Telerik MVC grid, together with AJAX binding to actions secured by [Authorize].

When the asp.net logged in session expires, if I trigger one of the grid actions, I get the following error message: "Error!The requested URL did not return JSON"

I want the ajax called actions to time out as a normal action would once the session has expired.

Any ideas? I've asked this a couple of times on the Telerik forums but have had no reply as yet.

TIA!


Solution

  • I finally found an answer on the telerik forums.

    I customised the Grid Error client side event: link <--dead link

    Edit: As the above link is dead, here is a code snippet. Hopefully it will help. I used this on the Grid declaration:

    .ClientEvents(events => events.OnError("onGridError"))
    

    and this is the javascript function it calls which simply supresses the error and redirects to the login page:

    function onGridError(e) {
    
        e.preventDefault();
        var xhr = e.XMLHttpRequest;
    
        document.location.href = '../Account/Login';
    } 
    

    Note: I don't think the middle line (var xhr...etc) actually does anything, looks redundant to me, just grabbed it from the codebase.