I am calling a web service from my MVC view and wanting to use the jquery ajax error functionality on exception throw.
I am trying to throw a custom created exception from my MVC business layer into my presentation layer controller and rethrow it as a json response.
I can successfully throw my custom exception, the issue is it comes as a HTML view. I have seen ways to declare a custom error response, but I was hoping to be able to directly rethrow the exception as JSON.
Any ideas?
Javascript:
$.ajax({
type: "POST",
url: 'create',
data: "{userDetails:" + JSON.stringify(details) + "}",
contentType: "application/json; charset=utf-8",
success: function (data) {
data = data.d;
redirectSuccess();
},
error: function(err) {
//display thrown exception here
}
});
CS
public JsonResult create(MyModel.New details)
{
try
{
Library.insert(details);
return Json(true);
}
catch (Exception ex)
{
throw;
}
}
Thanks in advance for any help!
Json
object.