Error in View message

Asked

Viewed 43 times

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:

inserir a descrição da imagem aqui

How can I solve this problem?

  • 1

    What is the result if you put a "console.log("Error :"+text[i]);" inside the for, before pushing the error ?

  • Error :The field "Description" must be filled in

  • Able to take out, thanks I gave a go to strip the elements that are with empty text.

  • 1

    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.

  • I don’t think I can reproduce since only the one that was making that mistake for now

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.