The grid is defined:-
@(Html.Kendo().Grid<
CMS_2013.Models.SeasonalProfile
>()
.Name("Grid")
.Events(e=>e.Edit("onEdit"))
.Columns(columns=>
{
columns.Bound(o => o.ID);
columns.Bound(o => o.Profile_Code);
columns.Bound(o => o.ProfileType);
columns.Bound(o => o.Description);
columns.Bound(o => o.Site);
columns.Bound(o => o.PATCLASS);
columns.Bound(o => o.Specialty);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(commands=>commands.Create())
.Editable(editable=>editable
.Mode(GridEditMode.PopUp))
.DataSource(dataSource=>dataSource
.Ajax()
.Model(m=>m.Id(p=>p.ID))
.Events(events => events.Error("error"))
.PageSize(10)
.Read(read=>read.Action("ReadProfiles","Profiles"))
.Create(create=>create.Action("InsertProfile","Profiles"))
.Update(update=>update.Action("UpdateProfile","Profiles"))
.Destroy(delete=>delete.Action("DeleteProfile","Profiles"))
)
.Pageable()
.Sortable()
.Filterable()
)
function
error(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);
}
}
This works fine, displaying the error message if the validation fails. However, I have two problems:-
- After displaying the alert, the edit form is closed, so the user can't correct their error - they have to start all over again
- Even though the record hasn't been saved - a new record is displayed in the grid, and only after refreshing the grid does it disappear.
How can I solve these two issues?
Thanks
10 Answers, 1 is accepted
Please take a look at this code library about Handling server-side validation errors during pop-up editing. It covers a case, similar to yours.
Let me know if this solves your issue.
Dimiter Madjarov
the Telerik team
Using the error code as per the example, it stopped the edit form closing, but no message was displayed.
So I just altered my original code to:-
function
error(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"
;
});
}
});
var
grid = $(
"#Grid"
).data(
"kendoGrid"
);
grid.one(
"dataBinding"
,
function
(e) {
e.preventDefault();
// cancel grid rebind if error occurs
});
alert(message);
}
}
Hello Oliver,
We are not aware of issues with the mentioned approach. You could find the example with a more recent Kendo UI version on the following documentation page.
Regards,Dimiter Madjarov
Telerik
OK, I figured out the reason. I had this code in addition:
function
onGridDataSourceRequestEnd(e) {
if
(e.type ==
"update"
|| e.type ==
"create"
) {
// this.read();
}
}
Removing it, keeps the popup open
Hello Oliver,
Thanks for the update.
Regards,Dimiter Madjarov
Telerik
Hi
I am trying to follow the example Handling server-side validation errors during pop-up editing UI for ASP.NET MVC Resources.
In the example the error relates to a specific field. I would like to use a kendo notification in the error style if for example a record has been deleted that another user is trying to edit. For example "Record no longer exists".
I have an example on a change password form but I cannot replicate it on a grid popup editor.
A possible solution might be using a custom popup editor for the grid.
http://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/custom-popup-editor
In the popup, based on a condition you could display the notification. I believe that these examples could assist you in implementing this functionality:
http://demos.telerik.com/aspnet-mvc/notification/templates
Regards,
Preslav
Telerik by Progress
I got the same problem as Oliver.
The line "this.read" has been commented out.
When are you going to refresh the grid after insertion or edition?
Edmond
The Grid could be refreshed in many different scenarios. One of them is when the user hits the update button when editing a record.
Could you please elaborate on your scenario? This will help me in providing assistance to the best of my knowledge.
Regards,
Preslav
Progress Telerik