Hello,
Would you please help me with the below issue?
We are returning the exception throw JSON object in the JQUERY call?
Below is how we are retuning the exception in the controller.
protected JsonResult ThrowJSONError(Exception e)
{
return Json(new { Message = e.Message }, JsonRequestBehavior.AllowGet);
}
below is how we capturing the exception:
var getSubDecisions = function(p) {
$.blockUI();
var url = window.location.pathname + "/ABC/XYZ";
url = url.replace('//', '/');
$.ajax({
url: url,
data: {
decisionId: $(p).val()
},
type: "POST",
datatype: "json",
complete: function () {
$.unblockUI();
},
success: function (result) {
},
error: function (xhr, status, error) {
handleServerException(xhr);
}
});
};
lets assume that there is an exception in the above AJAX. then it would go the error: (block) , and then
var handleServerException = function (xhr) {
var errors = [];
errors.push(xhr.responseText);
showErrors(errors, "DecisionForm");
};
var showErrors = function (errors, formName) {
clearValidationSummaryForm(formName);
var currentForm = $('form[name="' + formName + '"]');
$.each(errors, function (index, value) {
var errorMessage = value;
currentForm.find('div[data-valmsg-summary] ul').append('<li>' + errorMessage + '</li>');
});
currentForm.find('div[data-valmsg-summary]')
.removeClass('validation-summary-valid')
.addClass('validation-summary-errors');
currentForm.find('div.validationSummary').show();
};
As you can see above, when there is an exception in the AJAX call , it would go the Error black , from there it would to go handleServerException function and from there it would go to showErrors()... in the show errors function we are just trying to push the message to the UI... it works fine for the page validation erros but when it is an AJAX error.. it is throwing the bad request error instead of the exception we passed... but it works fine when we test through visual studio and it also works fine if we test application on the deployed server but.. outside the server it is throwing (pushing) bad request instead of the exception we are suppose to see..
Please let me know if you have any question about the issue.
Thanks for your help in advance.