How do you trigger the “error” callback in a jQuery AJAX call using ASP.NET MVC?

后端 未结 6 1489
心在旅途
心在旅途 2020-12-12 21:04

This is related to my question on how to handle errors from jQuery AJAX calls. Several responses suggested that I use the \"error\" callback to display any errors from a jQ

6条回答
  •  感情败类
    2020-12-12 21:32

    NOTE: Hey, this was posted before ASP.Net MVC even hit 1.0, and I haven't even looked at the framework since then. You should probably stop upvoting this.


    Do something like this:

    Response.StatusCode = (int)HttpStatusCode.BadRequest;
    actionResult = this.Content("Error message here");
    

    The status code should change depending on the nature of the error; generally, 4xx for user-generated problems and 5xx for server-side problems.

提交回复
热议问题