Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
150
How to handle Server Side Exceptions from MVC controller
posted

I am using the igGrid using the Grid Model approach. After Updating/Editing the grid post to an MVC controller. I would like an example how to handle Server Side errors and displaying the error to the returned View. 

Thanks

Parents Reply
  • 485
    Offline posted in reply to Eric

    Hello Eric,

     

    The grid API provides the scrollContainer method which would give you the scroll container – it would allow you set the scrollTop to zero and scroll the grid to the top when there is an error – that is exactly what these two lines of the snippet below do:

    let container = $('#grid').igGrid('scrollContainer')[0]

    container.scrollTop = 0;

     

    Setting the window.location.href to the according URL would allow you to redirect to another page if the server response is successful:

     

    window.location.href = "">https://www.someotherurl.com"

    You could then use success and error callback functions, which the “saveChanges” method would execute when the server responds back to the client. In case your popup has an id of “message”, the code might look like this one:

    $("#grid").igGrid("saveChanges", function (data) {
        window.location.href = " https://www.someotherurl.com "
    },
    function(jqXHR, textStatus, errorThrown) {
        $("#message").text("An error occurred while saving the changes. Error details: " + textStatus).fadeIn(3000).fadeOut(5000);
        let container = $('#grid').igGrid('scrollContainer')[0]
        container.scrollTop = 0;
    });
    

     

    Please let me know if you have some additional questions regarding this matter.

Children