2
如何使自定義命令更新telerik網格?例如,下面我有一個按鈕,通過自定義命令按鈕將該行的姓氏更新爲Peters。操作方法被調用,但網格未更新。Telerik MVC Grid自定義命令更新網格
@Html.Telerik()
.Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.Phone);
columns.Bound(o => o.State);
columns.Command(commands => commands.Custom("Stuff")
.Text("Change Name")
.DataRouteValues(route => route.Add(o => o.LastName)
.RouteKey("lastName"))
.Ajax(true)
.Action("Stuff", "Home"));
})
.DataBinding(dataBinding =>
{
dataBinding.Server().Select("Index", "Home", new { ajax = ViewData["ajax"] });
dataBinding.Ajax().Select("_Index", "Home").Enabled((bool)ViewData["ajax"]);
})
.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
.Footer((bool)ViewData["showFooter"]);
操作方法:
[GridAction]
public ActionResult Stuff(string lastName)
{
IEnumerable<Person> persons = GetPersons();
persons.First(p => p.LastName == lastName).LastName = "Peters";
return View(new GridModel(persons));
}