Getting row number if server side validation failed

2 posts, 0 answers
  1. Annie
    Annie avatar
    10 posts
    Member since:
    Oct 2014

    Posted 06 Nov 2014 Link to this post

    Hi,

    Is there a way to get the row number that caused the error when a server side validation failed

    for example in the function grid_error(e) in this example http://docs.telerik.com/kendo -ui/aspnet-mvc/helpers/grid/ajax-editing

    Thanks,
    Annie
  2. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 10 Nov 2014 Link to this post

    Hello Annie,

    By default there isn't any information for the model included in the errors returned from the server. It is possible to get the row by searching for the grid row that is currently in edit mode:
    function grid_error(e) {  
        if (e.errors) {
            var grid = $("#grid").data("kendoGrid");
            var row = grid.tbody.children(".k-grid-edit-row");
            ...
        }    
    }

    Another option would be to override the Errors property in the DataSourceResult so that it includes the model or model Id:
    var result = new[] { product }.ToDataSourceResult(request, ModelState);
    if (result.Errors != null)
    {
        result.Errors = new
        {
            Id = product.ProductID,
            errors = result.Errors
        };
    }
    return Json(result);
    and then use the Id to find the row.


    Regards,
    Daniel
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top