ASP.NET MVC必须匹配验证属性

Sha*_*ean 10 asp.net-mvc asp.net-mvc-3

我似乎无法找到要使用的注释,以确保2个或更多文本框是相同的.

例如:

public class NewPasswordModel
{
    public string NewPassword { get; set; }

    [MustMatch(Name="NewPassword")] // What is the correct thing to come here.
    public string NewPasswordRep { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Kim*_*jan 25

你可以使用原生的 CompareAttribute

public class NewPasswordModel
{
    public string NewPassword { get; set; }

    [Compare("NewPassword")]
    public string NewPasswordRep { get; set; }
}
Run Code Online (Sandbox Code Playgroud)