Popup editor: what to return when model validation fails?

2 posts, 0 answers
  1. Richard
    Richard avatar
    38 posts
    Member since:
    Mar 2011

    Posted 13 Jan 2016 Link to this post

    I have an MVC Razor app with the Kendo Grid using the popup editor modeled on the demo.  The popup comes up OK, and the model is invoked and does it's validation steps.  I do not use Entity Framework, the model has validation logic that applies business rules.  My problem is that when validation fails, or succeeds for that matter, the demo does not show what to return to the view/grid.  How are errors formatted for example? 

    My other question is what to return if successful?  The object the controller got from the editor is a singular object, not IQueriable or IEnumerable.  My grid is populated with data, and the model has already done the insert to the database if validation passed.  Do I refresh the grid, and if so, how can I make sure the user is kept in the same section of the grid?

    My controller code for Create is shown below (the return code shows an Intellisense error you can't see here):

    public ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request, BuyerAssignmentRecord bar)
        if (bar != null)
            if (bar.DepartmentOI == 0) { bar.DepartmentOI = -1; }
            if (bar.EmployeeOI == 0) { bar.EmployeeOI = -1; }
            if (bar.Validate())
                // todo: what to return if validation failed?
        return Json(new[] { BuyerAssignmentRecord }.ToDataSourceResult(bar, ModelState));

  2. Boyan Dimitrov
    Boyan Dimitrov avatar
    2026 posts

    Posted 15 Jan 2016 Link to this post

    Hello Richard,


    Straight to your questions: 


      1. When the validation fails I would suggest to add ModeState error as shown in the Handling Server-Side Validation Errors In Your Kendo UI Grid blog post. This is why the model state is return to the client-side. Of course the record should not be added to the data base. 


      2. It does not need to return a collection of items. You can return the newly created object as shown in the Ajax Editing article. 


    Boyan Dimitrov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top