0

I have the following Kendo grid:

 @(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))   
)

As you can see, I am using a popup dialog to edit a row. This creates a Kendo window with an update button, which will cause the Update method of the Notification controller to fire. If there is an error there, the error_handler specified above is called. This is it:

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

I display any errors, and the Kendo window is dismissed (actually, the order is, dismiss window, then errors are displayed).

What I want to do instead:

If there is an error after the user clicks the Update button, call the update method, get the error and display it, and NOT DISMISS THE WINDOW. This will allow the user to correct the error and try again.

Thanks for reading.

Scott
  • 2,456
  • 3
  • 32
  • 54
  • First, I would handle as many errors as possible client side. To handle server side errors is slightly complex: https://www.telerik.com/blogs/handling-server-side-validation-errors-in-your-kendo-ui-grid – Steve Greene Oct 30 '19 at 20:27
  • AFAIK, the only way is do all validation logic on save event, if there is any error, you can prevent default the event and show the error. By that way, the window will still display. – Long Le Oct 31 '19 at 09:36
  • Add `e.preventDefault();` to prevent dismissal. – Steve Greene Nov 01 '19 at 13:25

0 Answers0