I am wondering if I can send the error response I get from an Ajax call to my custom error view in MVC5.
Here is my very basic custom error view, which works for my controller error handling:
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
@{
// get innermost exception
var e = Model.Exception;
while (e.InnerException != null)
{
e = e.InnerException;
}
}
@e.Message
<br />
@Model.Exception.StackTrace
If I have an ajax call, I can do something like:
$.ajax
({
url: url,
data: data,
success: function() { /* do successful stuff */ },
error: function (jqXHR, textStatus, errorThrown)
{
alert("Code: " + jqXHR.status + "\n\nStatus: " + jqXHR.textStatus + "\n\nError: " + jqXHR.responseText);
}
});
But is there a good clean way to take that jqXHR and represent it with my error view? I thought about having the error function submit another call to the controller to throw a new error with the responseText but wasn't sure that was a good idea.. what if THAT action fails somehow?
Thank you in advance for any help and advice!