I have a form created using Ajax.BeginForm()
<% using (Ajax.BeginForm("UpdateCompanyShop", "CompanyShop", FormMethod.Post,
new AjaxOptions { OnSuccess = "updateList", OnFailure = "onError",
UpdateTargetId="slist", LoadingElementId = "loading" }))
controller action code is like below:
if(string.IsNullOrEmpty(company.Address))
return new HttpStatusCodeResult(418, "Please fill in address");
else if (company.DistrictID < 0)
return new HttpStatusCodeResult(418, "Please select district");
else
return new HttpStatusCodeResult(418, "Error saving data");
I used OnFailure=”onError” in AjaxOptions and I have my client-side script like this
function onError(response, status, error) {
var statusDescription = ***something***;
alert(statusDescription);
}
I use debugger in the JavaScript but cannot find the StatusDescription (the 2nd parameter in HttpStatusCodeResult)
Any idea how I can get status description? Or I should not use HttpStatusCodeResult at all? What is the proper way to return error (apart from validation) in AJAX submit?
Use
response.statusText:I wrote a post that provides somewhat more detail and a couple of examples:
Dealing with javascript or JSON results after an AJAX call with Ajax.ActionLink, unobtrusive AJAX and MVC 3