0

我正在使用 jQuery 将 ($.post) 发布到控制器操作并返回 JSON 结果。

如果有任何错误,我将返回带有 JSON 结果的错误消息,并使用模式将其显示给用户。

但是,我在拦截 AFT 异常时遇到了很多麻烦。

而不是抛出 500,我只想获取错误消息并将结果发送回用户。

...而且,如果我只是尝试处理错误,我无法弄清楚如何阻止它取消操作方法的执行

4

2 回答 2

1

You could trap this error in Application_Error and if the request was asynchronous send the proper JSON in the response containing the error message.

于 2010-07-09T10:55:14.700 回答
1

A token error is not meant to be handled by your code - it's a filter directive that happens before the Action is actually executed (a valid token is required before execution - this is for security).

You could probably get around this by creating your own ActionFilter - but this is Trouble (with a capital T) - I might suggest you find another way of doing it or let it fail. You could also do a test for a return value in your script - if nothing comes in you could show a message.

于 2010-07-09T08:15:13.843 回答