Search
Learn
Share

Validate confirm password in MVC with data attributes

Published by Profile Image DevDashboard on 17 December, 2015
630 views
Add the Compare attribute to your ConfirmPassword:

[Compare("Password")]

Example:

[Required(ErrorMessage = "Password is required")]
[DataType(DataType.Password)]
public string Password { get; set; }

[Required(ErrorMessage = "Confirm Password is required")]
[DataType(DataType.Password)]
[Compare("Password")]
public string ConfirmPassword { get; set; }