I know how to return HTTP status codes to indicate if an AJAX call failed or succeeded using the HttpStatusCode and HttpStatusCodeResult classes, and I know how to return objects using Json(), but now I need to return both a HttpStatusCode.BadRequest and a string containing the error message. I need to return the HttpStatusCode so the AJAX call goes to the error property, and can access the error message.
How would I do this in C#?
UPDATE I found this bit of code:
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "This is an error message");
That works alright and I can see the response in my browser. How would I extract the message part of this to display it in an alert through jQuery?
$.ajax()error handler, the error message should appear as the second argument,textStatus.response.statusText