This is a migrated thread and some comments may be shown as answers.

Clearing the dirty bit in Grids bound to Custom Models

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 24 May 2017, 02:45 AM

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?

[AcceptVerbs(HttpVerbs.Post)]
 public ActionResult Update([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<MenuProjectView> menuprojectviews)
        {
            try
            {
                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;
                        db.SubmitChanges();
                    }
                }
                return Json(new[] { menuprojectviews }.ToDataSourceResult(request, ModelState));
            }
            catch (Exception e1)
            {
                ModelState.AddModelError("", e1.Message);
                return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet);
            }
        }

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 26 May 2017, 05:59 AM
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.
Tags
Grid
Asked by
Neil
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or