ASP.NET MVC Ajax Form OnFailure never called!

The Ajax request is as follows:

In the controller action method, I tried to add a ModelState error, and throw an exception, but the response never throws OnFailure. It always calls OnSuccess regardless of the response. Maybe I missed something here.

Question: when will it call the OnFailure js method? Any samples will be appreciated.

thanks

+3
source share
2 answers

You need to return the HTTP error status code from your action. For example. 400, 404, 500.

try something like this:

throw new HttpException(404, "Not Found");
+11
source

MSDN, OnFailure , HTTP 200 . , (308), (307) (404) (400), OnFailure. HTTP .

0

Source: https://habr.com/ru/post/1708825/


All Articles