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

Duplicate Multiple Inserts on Update Insert and Delete commands

1 Answer 394 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jwize
Top achievements
Rank 1
jwize asked on 14 May 2013, 12:38 AM
The code (nothing wrong with the code)
@(Html.Kendo().Grid<CourseTypeViewModel>()
      .Name("MyCourseTypesGrid")
      .Editable(e => e.Mode(GridEditMode.InLine))
      .ToolBar(toolbar => toolbar.Create().Text("New Course"))
      .Columns(columns =>
          {
              columns.Bound(o => o.Title);
              columns.Bound(c => c.IsActive).Width(60);
              columns.Bound(c => c.DotCourse).Width(60);
              columns.Bound(c => c.RenewalInterval).ClientTemplate("#=RenewalInterval# (#=TimeFrame#)").Width(60);
              columns.Bound(c => c.TimeFrame).Width(80);
              columns.Command(command =>
                  {
                      command.Edit();
                      command.Destroy();
                  }).Width(200);
          }).Sortable().Pageable().Groupable()
        .DataSource(datasource => datasource
        .Ajax()
        .Model(p => p.Id(m => m.Id))
        .Create(create => create.Action("InsertCourseType", "Admin"))
        .Read(read => read.Action("CourseTypesGridData", "Admin"))
        .Update(update => update.Action( "UpdateCourseType", "Admin"))
        .Destroy(delete => delete.Action("DeleteCourseType", "Admin"))))

Just posting this because I saw some similar posts that seemed unanswered

I was having some problems in that whenever I updated an item in my grid I was finding new records filling up
my database.
Update the record
During debugging I was seeing that the insert method was being called multiple times instead of the expected update. This was very frustrating. 
10 new rows
I noticed that the the number of new phantom rows was equal to the number of records showing on the page. 
The solution
It seems that the update or insert for the grid is based on the id being zero. I don't know what this would mean for other types. Anyhow, the problem is that in my viewmodel code I had forgot to copy over the primarykey ids so they were all zero. 
The kendo grid
Apparently, decides to do an insert for every PrimaryKey equalling zero. If a non-zero value is there the update method is called. 

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 May 2013, 10:39 AM
Hi Jaime,

Thank you sharing this solution.
Your observations are correct - editing of the grid depends highly on the ID of the model. You may find more information on the subject in this topic.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
jwize
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or