我创建了可以创建、更新和删除数据的 Kendo UI Grid。但它不是在我的控制器中触发更新操作。
这是我的代码:
<script src="~/Scripts/Kendo/jquery.min.js"></script>
<script src="~/Scripts/Kendo/kendo.all.min.js"></script>
<script src="~/Scripts/Kendo/kendo.aspnetmvc.min.js"></script>
@(Html.Kendo().Grid<SkuMetadata>()
.Name("Grid")
.Columns(colums =>
{
colums.Bound(p => p.CompanyName).Width(100);
colums.Bound(p => p.BrandName).Width(100);
colums.Bound(p => p.ProductName).Width(100);
colums.Bound(p => p.SkuName).Groupable(false).Width(100);
colums.Command(command => {
command.Edit();
command.Destroy(); }).Width(160);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height: 500px;" })
.DataSource(dataSource =>
dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.PageSize(100)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.SkuId))
.Create(update => update.Action("CreateProducts", "Product"))
.Update(update => update.Action("UpdateProducts", "Product").Type(HttpVerbs.Post))
.Destroy(destroy => destroy.Action("DeleteProducts", "Product"))
.Read(read => read.Action("GetAllProducts", "Product"))))
我的行动是:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateProducts([DataSourceRequest] DataSourceRequest request, SkuMetadata skuMetadata)
{
return Json(_basicUnit.Skus.GetAllSku().ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteProducts([DataSourceRequest] DataSourceRequest request, SkuMetadata skuMetadata)
{
return Json(_basicUnit.Skus.GetAllSku().ToDataSourceResult(request));
}
创建和删除工作正常。我不明白为什么更新不起作用。我是否错过了任何参考或我做错了什么?