首页 > 解决方案 > How to use compare attribute to validate new password?

问题描述

Here is the code:

public string NewPassword { get; set; }
public string NewPasswordConfirm { get; set; }
public string NewFirstName { get; set; }
public string NewLastName { get; set; }
public AccountSettingsViewModel()
{
    Title = "Account";
}

I'm trying to make sure that the new password and new password confirm are the same using the Compare Attribute. How would i go about doing this?

标签: c#asp.netvalidationmodel-view-controllerpasswords

解决方案


您可以使用Compare DataAnnotation,参数将是模型中的 Password 属性。

[Required]
public string NewPassword { get; set; }
[Compare("NewPassword")]
public string NewPasswordConfirm { get; set; }

推荐阅读