1
[StringLength(255, MinimumLength=6, 
                   ErrorMessage = "Password can't be less that 6 characters"), 
                   Required, 
                   DataType(DataType.Password), 
                   Display(Name = "Password")]
public string Password { get; set; }

[StringLength(255, MinimumLength = 6), Required, DataType(DataType.Password), 
                   Compare("Password"), Display(Name = "Repeat password")]
public string RepeatPassword { get; set; }

如果用户输入的密码少于 6 个且密码不匹配。错误信息是:

密码不能少于 6 个字符 'Repeat password' 和 'Password' 不匹配。

如果重复密码小于 6 并且密码不匹配错误是:

“重复密码”和“密码”不匹配。字段重复密码必须是最小长度为 6 且最大长度为 255 的字符串。

如果是这种情况,我只希望出现“重复密码”和“密码”不匹配。我怎样才能做到这一点?

4

0 回答 0