I have a Web Api in which I have this code
@{
AjaxOptions addAjaxOpts = new AjaxOptions
{
// options will go here
OnSuccess = "getData",
OnFailure="selectView('add')",
HttpMethod = "Post",
Url = "/api/AccountManage/CreateAccount"
};
}
In the controller :
[HttpPost]
public void CreateAccount(CollaborateurModel item)
{
try{}
catch{
// return failure
}
}
I need to implement failure part
to execute OnFailure
method .
So how can I accomplish this task?
You can start by using Json Result (MSDN ref.)
Snippet example:
Then on the client side you call the controller using JQuery:
The fail function on Jquery will handle communication problems that you may have with client-server.
More info about JQuery you can find it here.