I have a Kendo Grid with some environments data. One of the fields of the grid is "isDefault" wich recieve 1 or 0 (for true or false). In the database I have a trigger that when some record is set to isDefault = 1 any other record is update to isDefault = 0, just to make sure there is only one default environment.The Kendo grid is working fine, it binds the data and updates the records just fine but after the update, the grid is not refreshing all the records and if there was, lets say, record 1 with isDefault =1 and I update record 4 to isDefault = 1 the trigger is fired and updates all others records to isDefault = 0 but the grid still showing record 1 with isDefault = 1 and now record 4 with isDefault = 1This is the code on my view:
and this is the code on my controller:
Thank you in advance for your answers.
Html.Kendo().Grid<Models.Environment>()
.Name(
"environmentGrid"
)
.Sortable()
.ToolBar(tb => tb.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Columns(cols =>
{
cols.Bound(c => c.Name).Width(150).Sortable(
true
);
cols.Bound(c => c.ConnectionString).Width(150).Sortable(
true
);
cols.Bound(c => c.Template).Width(150).Sortable(
true
);
cols.Bound(c => c.isDefault).Width(150).Sortable(
true
);
cols.Bound(c => c.StatusID).Width(150).Sortable(
true
);
cols.Command(command => { command.Edit();}).Width(60);
})
.DataSource(ds => ds
.Ajax()
.Model(model =>
{
model.Id(m => m.EnvironmentID);
})
.Read(r => r.Action(
"GetEnvironments"
,
"Admin"
))
.Update(update => update.Action(
"UpdateEnvironments"
,
"Admin"
))
.Create(update => update.Action(
"UpdateEnvironments"
,
"Admin"
))
)
and this is the code on my controller:
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult UpdateEnvironments([DataSourceRequest] DataSourceRequest dsRequest, Environment environment)
{
environment.ModifiedBy = userName;
if
(environment !=
null
&& ModelState.IsValid)
{
if
(environment.EnvironmentID != 0)
{
var toUpdate = xgr.EnviromentRepository.ListAll().FirstOrDefault(p => p.EnvironmentID == environment.EnvironmentID);
TryUpdateModel(toUpdate);
}
xgr.EnviromentRepository.Save(environment);
}
return
Json(ModelState.ToDataSourceResult());
}