I have an action :
[HttpPost]
public ActionResult MyAction(MyModel model)
{
...
if (model.MyCondition == true)
throw new Exception("MyMessage);
....
}
I’d like get the message “MyMessage” on the Ajax side :
onSuccess: function () {
...
},
onError: function (jqXHR, textStatus, errorThrown) {
//I'd like get "MyMessage" here
}
An idea how to do this ? When I check with the debugger I don’t see my string.
Implementing an error attribute is a good way. Also, I usually don’t throw the exception, but return a status code according to error. You can write to your response stream and access in js via
XMLHttpRequest.responseText:and in js: