0

Friends,

When I'm using compare validate fail even if correct because equalto bring a empty value to comparation I don't find any solution to this problem... The problem occurred at client side validation using validatejs.

This is my model:

[Required]
[StringLength(100, ErrorMessage = "A {0} deverá possuir {2} caracteres.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Senha")]
public string Senha { get; set; }

[DataType(DataType.Password)]
[Display(Name = "ConfirmSenha")]
[Compare("Senha", ErrorMessage = " O campo senha não corresponde a sua confirmação")]
public string ConfirmSenha { get; set; }

here is my view:

<div class="row">
    <div class="form-group col-sm-6">
        <label>Senha *</label>
        @Html.TextBoxFor(m => m.Senha, new { @class = "form-control required", type = "Password" })
        @Html.ValidationMessageFor(m => m.Senha, "", new { @class = "text-danger" })
    </div>
    <div class="form-group col-sm-6">
        <label>Confirmação de senha *</label>
        @Html.TextBoxFor(m => m.ConfirmSenha, new { @class = "form-control required", type = "Password" })
        @Html.ValidationMessageFor(m => m.ConfirmSenha, "", new { @class = "text-danger" })
    </div>
</div>

Image - debug with the problem

trmarco
  • 1
  • 1
  • https://stackoverflow.com/questions/4938078/using-dataannotations-to-compare-two-model-properties Take a look there, I think one of the answers will solve your problem. – Eduard Sep 19 '17 at 15:19
  • the problem is not at the server side... that's occur when event keydown is triggered at js validate and the target for comparison always return "" – trmarco Sep 19 '17 at 17:29
  • This has been incorrectly duped, but at this stage I am not inclined to reopen because its unclear what your asking (if the values of `Senha` and `ConfirmSenha` are exactly the same, then client side validation will not fail). And the image you have shown is referring to properties named `Email` and `ConfirmEmail`, which is not the code you have shown) –  Sep 19 '17 at 22:37
  • And as a side note, use `@Html.PasswordFor(...)` rather than `@Html.TextBoxFor(...)` and use `@Html.LabelFor()` to generate the labels –  Sep 19 '17 at 22:39
  • Once you better explain what your issue is then I will re-open it. –  Sep 19 '17 at 22:41

0 Answers0