3

The Ajax request is as follows:

In the controller action method I tried to add ModelState Error as well as throw an exception but response is never calling OnFailure. It always calls the OnSuccess regardless of response. May be I missing somthing here.

The question: When is it going to call the OnFailure js method? Any samples will be greatly appreciated.

Thanks

2 Answers 2

12

You need to return an HTTP error status code from your action. E.g. 400, 404, 500.

try something like this:

throw new HttpException(404, "Not Found");
Sign up to request clarification or add additional context in comments.

1 Comment

The answer listed above should work. You can check my question here which gives a bit more detail.
0

As per the MSDN definition, OnFailure is called when the HTTP response status is not in the 200 range. For instance if its a permanent Redirect (308), temporary redirect (307) Not Found (404) or Bad Request (400) then the OnFailure method is called. For a full list of HTTP response codes, see this wikipedia article

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.