I am using the CompareAttribute
in my ViewModel
like so:
[Required]
[StringLength(100, ErrorMessage = "{0} should be atleast {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Required]
[StringLength(100, ErrorMessage = "{0} should be atleast {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Comfirm password")]
[System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The passwords provided should be the same")]
public string ConfirmPassword { get; set; }
Together with jquery.validate.unobtrusive.js
this will trigger that my ComfirmPassword
property is not the same as the Password
property. But my values are the same!
I have been Googling like hell, and there is a lot of topics on this subject - but none of the "fixes" provided seems to work in my code.
The generated mark-up looks the following:
Password:
<input type="password" name="Password" id="Password" data-val-required="The field Password should be filled." data-val-length-min="6" data-val-length-max="100" data-val-length="Password should be atleast 6 charecters long." data-val="true" class="form-control">
ConfirmPassword:
<input type="password" name="ConfirmPassword" id="ConfirmPassword" data-val-required="The field Confirm password should be filled" data-val-length-min="6" data-val-length-max="100" data-val-length="Password should be atleast 6 charecters long." data-val-equalto-other="*.Password" data-val-equalto="'Confirm password' and 'Password' does not match." data-val="true" class="form-control">
I have noticed in the ConfirmPassword
property mark-up one of its data-attributes is: data-val-equalto-other="*.Password"
. Can this be somewhat wrong?