My grid has all crud operations working, the only problem is that after I save a new record, the grid does not update to the new ID from the controller. I have verified that the ID is being sent back from the controller with the model, but the grid does not update. Therefore any subsequent changes to the same record without a page refresh create a new record.
Controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddHoleToJob([DataSourceRequest] DataSourceRequest request, PlannedHolesVM viewModel)
{
_jobInfoService.AddHole(viewModel);
return Json(viewModel, JsonRequestBehavior.AllowGet);
}
Cshtml:
@(Html.Kendo().Grid<PlannedHolesVM>()
.Name("PlannedHolesKendoGrid")
.Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("HoleDetails"))
.Columns(c =>
{
c.Bound(m => m.ID);
c.Bound(m => m.HoleSectionLookupName);
c.Bound(m => m.HoleSectionTypeLookupHoleSectionType);
c.Bound(m => m.HoleSize);
c.Command(command =>
{
command.Edit();
command.Destroy();
});
})
.ClientDetailTemplateId("template")
.ToolBar(toolbar => toolbar.Create().Text("Add Hole"))
.DataSource(ds => ds
.Ajax()
.Model(model =>
{
model.Id(c => c.ID);
model.Field(c => c.JobID);
model.Field(c => c.JobID).DefaultValue(ViewBag.Jobid);
model.Field(c => c.HoleSectionID);
model.Field(c => c.HoleSectionTypeID);
})
.Read(read => read.Action("PlannedHolesGridData", "JobRecord", new { jobid = ViewBag.Jobid }))
.Destroy(delete => delete.Action("DeleteHoleFromJob", "JobRecord"))
.Create(create => create.Action("AddHoleToJob", "JobRecord"))
.Update(update => update.Action("AddHoleToJob", "JobRecord"))
)
.Events(e =>
{
e.DataBound("dataBound");
e.Save("refreshOnSave");
})
)
How do I make the grid update the new ID without calling read and going back to the database?
Create
andUpdate
methods. – CSharper