Kendo:处理 Ajax 数据请求中的错误 [英] Kendo: Handling Errors in Ajax Data Requests
本文介绍了Kendo:处理 Ajax 数据请求中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 MVC4 中使用 Kendo UI 我有一个 Grid 可以让 Ajax 调用将数据返回到控制器:
Using Kendo UI in MVC4 I have a Grid that makes Ajax calls for data back into the Controller:
public ActionResult SearchUser_Read([DataSourceRequest]DataSourceRequest request)
{
var data = CreateAnExcaptionHere();
return Json(data.ToDataSourceResult(request));
}
如何使用此调用通知页面出现错误?
How do I use this call to inform the page that there was an error?
推荐答案
如果您需要显示来自服务器的错误消息,您可以通过返回一个只设置了 Errors 属性的 DataSourceResult 对象来实现:
If you need to display an error message from the server then you can do it by returning a DataSourceResult object with only its Errors property set:
return this.Json(new DataSourceResult
{
Errors = "my custom error"
});
并使用它在客户端上获取它(由 .Events(events => events.Error("onError"))
行引用):
And pick it up on the client by using this (referenced by the .Events(events => events.Error("onError"))
line):
function onError(e, status) {
if (e.status == "customerror") {
alert(e.errors);
}
else {
alert("Generic server error.");
}
}
这篇关于Kendo:处理 Ajax 数据请求中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文