Clearing the dirty bit in Grids bound to Custom Models

2 posts, 0 answers
  1. Neil
    Neil avatar
    32 posts
    Member since:
    Aug 2016

    Posted 23 May 2017 Link to this post

    The following is my code for Updating. I have a custom view model that is a combination of 2 sql tables. The updates are processed successfully, but the dirty bit red triangle does not disappear. I have other grids in my solution that are bound directly to a specific sql table and those grids work as expected, the dirty bit disappears on successful updates to the database. What can I do in order to get the dirty bit cleared for my custom view?

     public ActionResult Update([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<MenuProjectView> menuprojectviews)
                    if (menuprojectviews != null && ModelState.IsValid)
                        foreach (var menuprojectview in menuprojectviews)
                            WorxMenus menu = db.WorxMenus.SingleOrDefault(s => s.Id == menuprojectview.MenuId);
                            menu.Title = menuprojectview.Title;
                            menu.Ordering = menuprojectview.Ordering;
                            menu.Date_Modified = DateTime.UtcNow;
                            Project project = db.Projects.SingleOrDefault(s => s.Id == menuprojectview.ProjectId);
                            project.ProjectType = (int)ProjectTypes.Schema;
                            project.SchemaName = menuprojectview.Title;
                            project.Date_Modified = DateTime.UtcNow;
                    return Json(new[] { menuprojectviews }.ToDataSourceResult(request, ModelState));
                catch (Exception e1)
                    ModelState.AddModelError("", e1.Message);
                    return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet);
  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 26 May 2017 Link to this post

    Hi Neil,

    First, you could inspect the browser's console and see if there are any JavaScript errors after the update request. You could also attach handler to the "error" event of the DataSource and see if it fires. If the response from the update request is successful you could see what is the content of that response, because it should contain a collection with the updated items.

    Finally, you could try calling the ToDataSourceResult method over the collection directly:
    return Json(menuprojectviews.ToDataSourceResult(request, ModelState));

    Best Regards,
    Konstantin Dikov
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top