views:

806

answers:

1

The Ajax request is as follows: <% using (Ajax.BeginForm("Update", new AjaxOptions { UpdateTargetId = "message", InsertionMode = InsertionMode.Replace, OnSuccess = "success", OnFailure = "error" })) { %>

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

+5  A: 

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");
DSO
Thank you for the answer
Bharat