0
I have a VIEW called Change Password and in it I have a Current Password field, a New password field and a New Password Confirmation field.
The three fields pass through the same control filter for these password, whose rule is that the password must be a mandatory field and contain between 8 and 15 elements.
My problem is: when the filter is activated in the first password field (if the password is not within the rules), the error message appears in all 3 password fields, and not only in the one being filled in.
Any hint on how to isolate these components and make the error message only be shown in the field that does not have the correct information?
<div class="row">
<div class="col-sm-12 col-sm-offset-4"><h2>Alterar senha do sistema</h2></div>
</div>
<br>
<div class="container">
<div class="middle">
<form>
<!--campo senha atual-->
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<div class="form-group">
<label>Senha Atual</label>
<input asp-for="Password" type="password" id="inputPassword" class="form-control" required>
@Html.ValidationMessageFor(model => model.Password)
</div>
</div>
</div>
<!-- nova senha-->
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<div class="form-group">
<div class="input-group">
<label>Nova Senha</label>
<input asp-for="Password" type="password" id="inputPassword" class="form-control" placeholder="Entre 8 e 15 caracteres" required>
</div>
@Html.ValidationMessageFor(model => model.Password)
</div>
</div>
</div>
<!--confirmar nova senha-->
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<div class="form-group">
<div class="input-group">
<label>Confirme a nova senha</label>
<input asp-for="Password" type="password" id="inputPassword" class="form-control" placeholder="Entre 8 e 15 caracteres" required>
</div>
@Html.ValidationMessageFor(model => model.Password)
</div>
</div>
</div>
<br>
<!--botao salvar-->
<div class="col-sm-1 col-sm-offset-4">
<button type="submit" class="btn btn-success btn-block">Salvar</button>
</div>
</form>
<!--link cancelar-->
<div class="col-sm-1">
<a href="#" class="forgot-password">Cancelar</a>
</div>
</div>
</div>
This is my filter for the password field
#region Senha
[Required(ErrorMessage = "Campo obrigatório")]
[StringLength(15, MinimumLength = 8, ErrorMessage = "Sua senha deve ter entre 8 e 15 caracteres.")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
#endregion
mvc
= architectural standard /asp.net-mvc
= technology specifies that it happens to be based on "mvc", thenmvc
!=asp.net-mvc
.......................... Please read the correct usage description when selecting the tags. PS: Do not use "Code snippet" (Stack Snippets) without need, read: http://pt.meta.stackoverflow.com/q/2115/3635. Welcome.– Guilherme Nascimento