gpt4 book ai didi

kendo-ui - KendoUI 网格在更新后保持编辑模式

转载 作者:行者123 更新时间:2023-12-02 08:41:49 25 4
gpt4 key购买 nike

我正在使用 AJAX 进行绑定(bind) (v2013.1.319) 的 KendoUI 网格使用 ASP.NET MVC 服务器包装器,并且正在使用内联编辑。当我编辑一条记录并点击更新时,帖子出现在服务器上并且记录被成功保存。我按照文档建议返回 JSON 响应,但 KendoUI 网格保持编辑模式。如果我单击取消,底层本地数据不会反射(reflect)更改。如果我刷新,则更改会正确显示。我需要一些帮助来找出更新不起作用的原因。创建和删除函数工作正常。

<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());
}

最佳答案

显然有一个 breaking change在影响Kendo Q1 2013 版本2013.1.319 的新版jQuery 中。成功的更新和销毁请求从服务器返回空结果。这会触发错误,因为空结果不是有效的 JSON。

此时有2个分辨率:
1) 获取最新的 KendoUI 内部版本,因​​为它有一个修复程序。
2) 返回一个序列化为 JSON 的虚拟对象。

return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());

关于kendo-ui - KendoUI 网格在更新后保持编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15927795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com