This is a migrated thread and some comments may be shown as answers.

KendoUI MVC Grid - Addnew or Update record with ajax and server side validation

6 Answers 426 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Srinivasan
Top achievements
Rank 1
Srinivasan asked on 01 Nov 2012, 10:09 PM

I have implemented inline editing with Knedo UI MVC grid with Ajax binding, Server side validation handled in controller and sending the error back using -

ModelState.AddModelError("Error: ", ex.Message);

@(Html.Kendo().Grid<AnalyticsServiceWeb.ViewModel.SomeViewModel>() .Name("Grid") .Columns(columns => { columns.Bound(p => p.Name); columns.Bound(p => p.Path); columns.Bound(p => p.Space); columns.Command(command => { command.Edit(); command.Destroy(); }); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.InLine)) )

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

The server side error message is getting displayed when there is a server side exception, but it still completes the action in UI, i mean it adds the new record to the grid and update as well even though there is server side exception.

Is there any way to retain the state of UI before the action start?, it supposed to work in that way, not sure if i am missing anything?

Thanks in advance

6 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 06 Nov 2012, 04:02 PM
Hello,

I would suggest you to check this code library project which demonstrates how to prevent the Grid from rebinding and keep it in edit mode when there are server side errors.

http://www.kendoui.com/code-library/mvc/grid/handling-server-side-validation-errors-during-pop-up-editing.aspx


Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Srinivasan
Top achievements
Rank 1
answered on 06 Nov 2012, 11:23 PM
The server side validation code you posted works with add new record, update existing record, but not the deletion (Ajax binding)
I am getting below exception on delete, could you please let me know if i am missing anything?


  1. Uncaught TypeError: Cannot read property 'element' of null
    1. (anonymous function)
    2. Class.extend.triggerkendo.all.min.js:9
    3. h.extend.refreshkendo.all.min.js:9
    4. Class.extend.triggerkendo.all.min.js:9
    5. o.extend._processkendo.all.min.js:9
    6. o.extend._changekendo.all.min.js:9
    7. (anonymous function)kendo.all.min.js:9
    8. o.fireWithjquery.min.js:2
    9. g.(anonymous function).call.c.successkendo.all.min.js:9
    10. o.fireWithjquery.min.js:2
    11. d
0
Petur Subev
Telerik team
answered on 12 Nov 2012, 10:01 AM
Hello again Srinivasan,

The JavaScript error which you see is because there is no editing element when editing a record

grid.editable.element


The above is only available when inserting or editing a record. You need to inform the user in a different way that the destroy operation has caused errors.


Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Pat
Top achievements
Rank 1
answered on 14 Dec 2012, 08:45 PM
The problem with the referenced link is that it applies to pop up editting.  It doesn't work for me with inline editting.
0
Petur Subev
Telerik team
answered on 19 Dec 2012, 02:22 PM
Hello Pat,

What do you mean by 'doesn't work'? I tried to change only the following line and the validation seems to be triggered and displayd again.

.Editable(editable => editable.Mode(GridEditMode.InLine))


Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Pat
Top achievements
Rank 1
answered on 19 Dec 2012, 03:02 PM
It does work for me now.

I initially was getting a javascript error.  But now it works.
Tags
Grid
Asked by
Srinivasan
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Srinivasan
Top achievements
Rank 1
Pat
Top achievements
Rank 1
Share this question
or