Search code examples
kendo-uikendo-gridkendo-asp.net-mvc

Kendo UI Grid - Deleting a row, an error occurs but the row is still removed from the grid


I'm using Kendo UI Grid MVC. When a row is deleted from the grid, and an error occurs on the server, an error is displayed to the user (based on what is stored in ModelState), as it should, but the row is still removed from the grid when it shouldn't be removed. How can I get prevent Kendo from removing the row from the grid on a server error?


Solution

  • As workaround you can try to catch grid dataSource error event and use canelChanges() method if it occured:

    ...
    .DataSource(dataSource => dataSource
        ...
        .Events(events => events.Error("onGridError"))
    )
    

    And in JavaScript:

    function onGridError() {
        var grid = $("#grid").data("kendoGrid");
        grid.cancelChanges();
    }