在 MVC4 中使用 Kendo UI,我有一个网格,它使 Ajax 将数据调用回 Controller :
public ActionResult SearchUser_Read([DataSourceRequest]DataSourceRequest request)
{
var data = CreateAnExcaptionHere();
return Json(data.ToDataSourceResult(request));
}
如何使用此 call 通知页面有错误?
最佳答案
如果需要显示来自服务器的错误消息,则可以通过返回仅设置了Errors属性的DataSourceResult对象来实现:
return this.Json(new DataSourceResult
{
Errors = "my custom error"
});
并使用以下命令在客户端上将其拾取(由
.Events(events => events.Error("onError"))
行引用):function onError(e, status) {
if (e.status == "customerror") {
alert(e.errors);
}
else {
alert("Generic server error.");
}
}
关于asp.net-mvc - Kendo:处理Ajax数据请求中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13653662/