I can't localize validate: 'Confirm password' and 'Password' do not match. in MVC5
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] //Why not display this message???????
public string ConfirmPassword { get; set; }
Please help me localize it.
Data Annotation to validate confirm password.
When creating users in MVC application want users to enter strong password and re-enter password to confirm. Add DataAnnotations namespace to login class. DataAnnotations have Compare attribute. [Compare("Password", ErrorMessage = "Confirm password doesn't match, Type again !")]
You have 2 options to solve this bug:
--Option 1
Change:
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
to
[System.Web.Mvc.Compare("Password", ErrorMessage = "Your custom error message")]
--Option 2 (I recommend this one)
We need to update our ASP.NET MVC 5. In your Visual Studio go to the Package Manager Console and type:
PM> update-package
You migh get an error in the:
public ApplicationDbContext()
: base("DefaultConnection")
{
}
That error is caused by the update in the internal structure of MVC 5. To solve that error do this: https://stackoverflow.com/a/23090099/2958543
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With