1
I have that code:
$.ajax({
url: "/InternalAuditRecord/SaveInternalAuditRecord",
type: "post",
data: $("form#internalAuditRecordRegisterForm").serialize()+"&idResponsibles="+responsibles+"&idAuditors="+auditors,
success: function (res) {
if (typeof (res) == "object") {
if (res.success) {
window.location.replace("/InternalAuditRecord/InternalAuditRecord");
}
else {
console.log(res);
//flashMessage();
if ($("#Name").val() == "") {
$("#Name").addClass(validationClassErrosType.input)
}
validationCheckImage($("#Name"), $("#Name").parent());
var text = String(res).split(",");
var errorMessages = ["<ul>"];
for (var i = 0; i < text.length; i++) {
errorMessages.push("<li>"+text[i]+"<li>");
}
errorMessages.push("</ul>");
$(".validation-summary-errors").html(errorMessages.join(""));
loadSwitches();
}
}
My controller:
if (!ModelState.IsValid){
ModelState.OrderByKeys(criticalAnalysisRecord.GetValidationOrder());
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json(ModelState.GetModelStateErros());
}
And the View:
<div id="messages">
<div class="validation-summary-errors" data-valmsg-summary="true">
</div>
</div>
That puts the message in the View however this going a tag li too, as can be observed in the image:
How can I solve this problem?
What is the result if you put a "console.log("Error :"+text[i]);" inside the for, before pushing the error ?
– Bruno
Error :The field "Description" must be filled in
– Bruno H.
Able to take out, thanks I gave a go to strip the elements that are with empty text.
– Bruno H.
I’m glad I did, but it would be interesting to see why blank messages are coming when they shouldn’t. If you can’t create some problems with these unnecessary codes to fix these bugs.
– Bruno
I don’t think I can reproduce since only the one that was making that mistake for now
– Bruno H.