I can not show the error in my view

1

Well, I have a view and I can not show the error messages, the code is very large and put in a summarized form but needs some part I'm editing.

Controller Before it was like this:

if (!ModelState.IsValid)
{
  return PartialView("InternalAuditRecordForm", criticalAnalysisRecord);
}

Picture of when knockoutjs stops working:

Nowitlookslikethis:

if(!ModelState.IsValid){ModelState.OrderByKeys(criticalAnalysisRecord.GetValidationOrder());Response.StatusCode=(int)HttpStatusCode.BadRequest;returnJson(ModelState.GetModelStateErros());}

Imageofrunningknockoutjs:

ThejavaScript:

functionsaveInternalAuditRecord(){removeAllPlaceHolder();clearErrorsMessages();responsibles="";
            $("select#Responsibles option").each(function () {
                responsibles += $(this).val() + ",";
            });
            auditors = "";
            $("select#Auditors option").each(function () {
                auditors += $(this).val() + ",";
            });
            $.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 {
                            flashMessage();
                        }
                    }
                    else {
                        $("article.container_12").replaceWith(res);

                        validationCheckImage("#Name", "#span_location");
                        //$("#Name").addClass("input-validation-error");

                        loadSwitches();
                        $('html, body').animate({ scrollTop: 0 }, 'fast');
                    }
                }, error: function () {
                    $("#messages").html("<p class=\"message error no-margin\" style=\"margin-bottom:10px !important;\">Ocorreu um erro durante a gravação dos dados.</p>");
                }

            });
        }

My Entitie:

public class InternalAuditRecord
    {
        [Key]
        public int InternalAuditRecordID { get; set; }

        [Required(ErrorMessage = "O campo \"Descrição\" deve ser preenchido")]
        public string Name { get; set; }
}

And the DIV in the view:

 <div id="messages">
     <div class="validation-summary-errors" data-valmsg-summary="true">
     </div>
 </div>

In this way it brings the error however knockoutjs stops working, with the old controller format. Now the new knockoutjs is still working but I can not display the error in my view.

    
asked by anonymous 18.07.2017 / 15:37

0 answers