I cannot show error in my view

Asked

Viewed 22 times

1

Well, I have a view and I can not show the error messages, the code is very large and put in a summary but need some part I am editing.

Controller Before it was like this:

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

Screenshot of when knockoutjs stops working:

inserir a descrição da imagem aqui

Now it’s like this:

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

Picture of knockoutjs working:

inserir a descrição da imagem aqui

The Gospels:

function saveInternalAuditRecord() {
            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>

This way it brings the error but knockoutjs stops working, with the old format of the controller. Now the new knockoutjs keeps working but I can’t show the error in my view.

No answers

Browser other questions tagged

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