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
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
I am getting below exception on delete, could you please let me know if i am missing anything?
- Uncaught TypeError: Cannot read property 'element' of null
-
(anonymous function)
-
Class.extend.triggerkendo.all.min.js:9
-
h.extend.refreshkendo.all.min.js:9
-
Class.extend.triggerkendo.all.min.js:9
-
o.extend._processkendo.all.min.js:9
-
o.extend._changekendo.all.min.js:9
-
(anonymous function)kendo.all.min.js:9
-
o.fireWithjquery.min.js:2
-
o.firejquery.min.js:2
-
g.(anonymous function).call.c.successkendo.all.min.js:9
-
o.fireWithjquery.min.js:2
-
d
-
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
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
I initially was getting a javascript error. But now it works.