I have an MVC webapp that validates form input from an Ajax post in the controller like so:
if (string.IsNullOrWhiteSpace(txtNewTAmount) || !decimal.TryParse(txtNewTAmount, out _tmpD))
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "Please Enter a Valid Transaction Amount.");
When this check fails, I have a toastr pop-up that displays the error message. In the above example, it displays "Please Enter a Valid Transaction Amount.". Here is the relevant JS code for this operation:
Ajax Post:
function submitNewTransaction() {
var frm = $('#insertTrans');
var postData = frm.serialize()
$.ajax({
type: "POST",
url: '@Url.Action("Action","Controller")',
data: postData,
success: function (data) {
OnSuccessNewTransaction(data);
},
error: function (data) {
OnFailureNewTransaction(data);
}
});
}
OnFailure:
function OnFailureNewTransaction(response) {
toastr.error('Error Saving New Transaction: <br /> <strong>' + response.statusText + '</strong>', '', { progressBar: true, timeOut: 5000 });
}
This works fine over regular HTTP, but when using HTTPS all the custom error messages in response.statusText are overwritten with just "error". I'm not positive, but I suspect IIS might be the culprit here. Is there any way I can prevent this from happening? Or should I just move all of my validation client side? Thanks in advance for any help with this matter!