开发者

Is ASP.NET MVC definition of an AJAX success to narrow? how do i deal with other status codes?

开发者 https://www.devze.com 2023-01-07 04:24 出处:网络
I am using Ajax.BeginForm(... in asp.net MVC 2.0 I would like to return HTTP status codes from my contr开发者_StackOverflowoller.

I am using Ajax.BeginForm(... in asp.net MVC 2.0

I would like to return HTTP status codes from my contr开发者_StackOverflowoller.

For example:

  • 400 (validation error)
  • 200 (if everything is OK)

I would like to use new AjaxOptions{UpdateTargetID="ajax-form", OnSuccess="...", OnFailure="..."} to handle these scenarios, however If I return a statuscode of 400 the UpdateTarget does not update my html.

Is there a way to have this update occur for "failures" as well as successes?


Typically, servers don't return meaningful content for 4** errors. When they do, browsers don't tend to bother to display it. So, no, I don't think MVC is being overly finicky here.

If you think 400 is the right response from your server, then your choices are to use $.ajax() instead of Html.BeginForm or to handle OnFailure.

0

精彩评论

暂无评论...
验证码 换一张
取 消