The code (nothing wrong with the code)
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.
@(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.