首页 > 解决方案 > Kendo Window - 使用自定义更新

问题描述

我有以下剑道网格:

 @(Html.Kendo().Grid<Mizuho.AMS.Models.AMSServiceProcessNotificationModel>()
    .Name("grd")
    .ToolBar(toolBar =>
    {
        toolBar.Create();
    })
    .Sortable()
    .Scrollable(a => a.Height("auto"))
    .Filterable(s => s.Enabled(false))
    .Selectable(s => s.Enabled(false))
    .Pageable(p => p.Enabled(true).Refresh(true).PageSizes(new List<string> { "all", "10", "15", "20", "50" }))
    .HtmlAttributes(new { style = "width: 100%;" })
    .Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("NotificationEditor").Window(w => w.Width(700)))
    .Columns(columns =>
    {
        columns.Bound(s => s.ProcessId).Width(90);
        columns.Bound(s => s.NotificationType).Width(140);
        columns.Bound(s => s.NotificationAction).Width(140);
        columns.Bound(s => s.Parameters).Width(680);
        columns.Command(cmd => { cmd.Edit(); cmd.Destroy(); });
    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .PageSize(15)
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Id(s => s.ID);
        })
        .Read(read => read.Action("Read", "Notification"))
        .Create(create => create.Action("Create", "Notification"))
        .Update(update => update.Action("Update", "Notification"))
        .Destroy(destroy => destroy.Action("Destroy", "Notification"))
    )        
    .Resizable(resize => resize.Columns(true))   
)

如您所见,我正在使用弹出对话框来编辑一行。这将创建一个带有更新按钮的 Kendo 窗口,这将触发 Notification 控制器的 Update 方法。如果那里有错误,则调用上面指定的 error_handler。就是这个:

function error_handler(e) {
    if (e.errors) {
        var message = "";
        $.each(e.errors, function (key, value) {
            if ('errors' in value) {
                $.each(value.errors, function () {
                    message += this + "\n";
                });
            }
        });
    }
}

我显示任何错误,然后关闭 Kendo 窗口(实际上,顺序是关闭窗口,然后显示错误)。

我想做的是:

如果用户单击更新按钮后出现错误,则调用更新方法,获取错误并显示它,而不是关闭窗口。这将允许用户更正错误并重试。

谢谢阅读。

标签: kendo-uikendo-gridkendo-asp.net-mvc

解决方案


推荐阅读