This question is locked. New answers and comments are not allowed.
Hi Telerik,
I was hoping that you might be able to confirm that the following should work or not on the initial binding?
Should the OnError event get thrown when you apply ModelState.AddModelError during the initial bind of the grid via ajax, or do I need to set Response.StatusCode = 500 everytime to create the error but this will not create a modelstateerror
I am using version 2012.1.214
Please see the follwing code below:
VIEW
Javascript Handler
Controller
I was hoping that you might be able to confirm that the following should work or not on the initial binding?
Should the OnError event get thrown when you apply ModelState.AddModelError during the initial bind of the grid via ajax, or do I need to set Response.StatusCode = 500 everytime to create the error but this will not create a modelstateerror
I am using version 2012.1.214
Please see the follwing code below:
VIEW
@{
Html.Telerik().Grid<
TaskDto
>()
.Name("Tasks")
.ClientEvents(events => { events.OnError("Grid_onError"); }
)
.Columns(columns =>
{
columns.Bound(o => o.Title).Title("Title");
})
.Sortable()
.DataBinding(
dataBinding => dataBinding.Ajax()
.Select("_Tasks", "Task")
)
.EnableCustomBinding(true)
.Render();
}
Javascript Handler
function Grid_onError(args) {
alert(args.textStatus);
if (args.textStatus == "modelstateerror" && args.modelState) {
var message = "Errors:\n";
$.each(args.modelState, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
args.preventDefault();
alert(message);
}
}
Controller
[HttpPost]
[GridAction(EnableCustomBinding = true)]
public ActionResult _Tasks(GridCommand command)
{
try
{
return View(new GridModel<
TaskDto
>() { Data = _proxy.CurrentTasks() });
}
catch(Exception exception)
{
// Response.StatusCode = 500;
ModelState.AddModelError("Error", "Proxy error.");
return View(new GridModel<
TaskDto
>() { Data = new List<
TaskDto
>() { } });
}
}
}