Kendo: Handling Errors in Ajax Data Requests

前端 未结 5 2055
再見小時候
再見小時候 2020-12-17 08:23

Using Kendo UI in MVC4 I have a Grid that makes Ajax calls for data back into the Controller:

<         


        
5条回答
  •  时光取名叫无心
    2020-12-17 08:33

    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"
                });
    

    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.");
        }
    }
    

提交回复
热议问题