我正在使用 ASP.NET MVC Server Wrappers 为 KendoUI Grid 使用 AJAX 进行绑定(v2013.1.319),并且正在使用内联编辑。当我编辑一条记录并单击更新时,该帖子发生在服务器上并且记录已成功保存。我按照文档的建议返回 JSON 响应,但 KendoUI Grid 仍处于编辑模式。如果单击取消,则基础本地数据不会反映更改。如果我刷新,更改就会正确显示。我需要一些帮助来找出更新不起作用的原因。创建和删除功能工作正常。
<div style="width: 800px">
@(Html.Kendo().Grid<RoleGridModel>()
.Name("grdRoles")
.Columns(columns =>
{
columns.Bound(r => r.Name).Width(200);
columns.Bound(r => r.Description).Width(300);
columns.Command(command => {
if (security.CanAdd || security.CanUpdate) command.Edit();
if (security.CanDelete) command.Destroy();
command.Custom("Manage Access").Click("manageAccess");
})
.Width(300);
})
.Groupable(grouping => grouping
.Enabled(false))
.Events(events => { if (security.CanAdd && !security.CanUpdate) events.DataBound("function() { this.table.find('.k-grid-edit').hide(); }"); })
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(r => r.RoleId))
.Events(events => events.Error("error_handler"))
.Read(read => read.Action("Index", "Roles", new { area = "Setup" }))
.Create(create => create.Action("Create", "Roles", new { area = "Setup" }))
.Update(update => update.Action("Edit", "Roles", new { area = "Setup" }))
.Destroy(destroy => destroy.Action("Delete", "Roles", new { area = "Setup" }))
.Sort(sort => sort.Add(r => r.Name).Ascending())
.PageSize(10))
.Filterable(filtering => filtering
.Enabled(true))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable(paging => paging
.Enabled(true)
.Info(true)
.PageSizes(false)
.Refresh(true))
.Scrollable(scrolling => scrolling
.Enabled(false)
.Height(400)
.Virtual(false))
.Sortable(sorting => sorting
.Enabled(true)
.AllowUnsort(false)
.SortMode(GridSortMode.SingleColumn))
.ToolBar(toolbar => { if (security.CanAdd) toolbar.Create(); })
)
//
// POST: /Setup/Roles/Edit
[HttpPost]
public ActionResult Edit([DataSourceRequest] DataSourceRequest request, RoleGridModel model)
{
if (ModelState.IsValid && model != null)
{
try
{
Role r = Mapper.Map<RoleGridModel, Role>(model);
r.AppContext = this.AppContext;
r.SubscriberId = this.AppContext.SelectedSubscription.SubscriberId;
r.SubscriptionId = this.AppContext.SelectedSubscription.SubscriptionId;
r.ModifyDate = DateTime.UtcNow;
r.IsNew = false;
r.IsMarkedForDelete = false;
r.HasChanges = true;
r.Save();
}
catch (Exception ex)
{
LogException(ex);
ModelState.AddModelError("", "Unable to update role. " + ex.Message);
}
}
return Json(ModelState.ToDataSourceResult());
}