in MVC3 you can add validation to models to check if properties match like so:
public string NewPassword { get; set; }
[Compare("NewPassword",
ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
Is there a way to check that two properties differ like in the following make-believe code?
[CheckPropertiesDiffer("OldPassword",
ErrorMessage = "Old and new passwords cannot be the same")]
public string OldPassword { get; set; }
public string ConfirmPassword { get; set; }
I would do checking in the controller.
In controller:
if(model.ConfirmPassword == model.OldPassword ){
ModelState.AddModelError("ConfirmPassword", "Old and new passwords cannot be the same");
}
In View:
@Html.ValidationMessage("ConfirmPassword")
Hope this helps
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