Hi,
I have a Kendo grid setup and I would like my controller's update action to assign a custom error to the ModelState and have that picked up on the client side. This is not an actual error, but more of a flag I can catch on the client side to initiate a redirect to another page (similar to the concept posted here: Redirect to another page after update in Kendo grid with inline edit in UI for ASP.NET MVC | Telerik Forums
My issue is that I cannot get the error handler to fire on the client side. Here is my controller action (I've reduced it down to just the error handling for simplicity):
[HttpPost]
public JsonResult Status_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<StatusViewModel> changedEntries)
{
ModelState.AddModelError("UserRedirect", "UserRedirect needed");
var result = ModelState.ToDataSourceResult();
return Json(result);
}
Here is my grid setup:
@(Html.Kendo().Grid(Model)
.Name("status-grid")
.Columns(c =>
{
// snip column setup
})
.ToolBar(toolbar =>
{
toolbar.Custom().Text("Save changes and submit").HtmlAttributes(new { id = "saveButton" });
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Scrollable(s => s.Height(850))
.Navigatable()
.Events(events =>
{
events.Edit("onEdit");
events.Navigate("onNavigate");
})
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("onError"))
.Model(model =>
{
// snip model fields
})
.Update("Status_Update", "Status"))
)
Finally, here is my error handler function:
<script type="text/javascript">
function onError(e) {
alert("Error handler fired");
}
</script>
I feel like this is a pretty vanilla setup, so I'm not sure why it isn't working. I've tried quite a few variations and the error handler never executes. I have no errors in the console. Here is the JSON that is being received on the client side. Can anyone see anything I am doing wrong, or tell me a better way to redirect the user to another page after the AJAX Update action finishes running? Thanks!!
{errors: {ValidationRedirect: {errors: ["ValidationRedirect needed"]}}} errors: {ValidationRedirect: {errors: ["ValidationRedirect needed"]}} ValidationRedirect: {errors: ["ValidationRedirect needed"]} errors: ["ValidationRedirect needed"] 0: "ValidationRedirect needed"