MVC 3 Ajax.ActionLink 如何获取 onFailure 处理程序中的状态代码?
在 Ajax 操作链接调用的操作中,我需要根据当前条件抛出 HttpException。根据这些条件,HttpException 具有不同的代码。
如何获取 onFailure 处理程序中的状态代码?
In the action called by an Ajax action link, I need to throw an HttpException based on the current conditions. Depending on those conditions, the HttpException has a different code.
How do I get the status code in the onFailure handler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我发现你不需要抛出 HttpException。相反:
onFailure 处理程序应该如下所示:
对我来说,现在唯一的问题是如何自己处理 401,而不是显示登录页面的 MVC。如果是 401,则不会显示警报,但对于任何其他状态代码,这都有效。
I had the same problem, and I figured out you do not need to throw an HttpException. Instead do:
The onFailure handler should look like this:
For me the only problem is now how to handle the 401 myself instead of MVC showing the logon page. In case of a 401 the alert is not shown, but with any other statuscode this works.
只需将
AjaxOptions.OnFailure
属性设置为如下函数:请参阅这篇文章:https://www.experts-exchange.com/questions/28583187/MVC-Ajax-BeginForm-how-to-处理 OnSuccess-and-OnFailure-from-Controller.html
Simply set
AjaxOptions.OnFailure
property to a function like this:See this post: https://www.experts-exchange.com/questions/28583187/MVC-Ajax-BeginForm-how-to-handle-OnSuccess-and-OnFailure-from-Controller.html