Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Confirm password' and 'Password' do not match. MVC5

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.

like image 659
vietdv Avatar asked Nov 15 '13 15:11

vietdv


People also ask

What annotation must be used for comparing passwords?

Data Annotation to validate confirm password.

What is my MVC password and 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 !")]


1 Answers

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

like image 177
mejiamanuel57 Avatar answered Sep 29 '22 13:09

mejiamanuel57