2010-03-15 189 views

回答

0

这里没有一个内置的,但是,你可以自己制作。请参阅this link,其中显示了“PropertiesMustMatchAttribute”,它就是您要查找的内容。

42

如果您正在使用ASP.Net MVC 3,你可以使用System.Web.Mvc.CompareAttribute

[Required] 
[DataType(DataType.Password)] 
public string Password { get; set; } 

[Required] 
[DataType(DataType.Password)] 
[Compare("Password")] 
public string PasswordConfirm { get; set; } 
+5

为什么这是在system.web.mvc而不是dataAnnotations?不应该在我的模型项目中引用system.web.mvc。多烦人。 – 2011-09-29 19:49:30

+11

在.Net 4.5中它也在System.Component.DataAnnotations中。 – Aligned 2012-08-23 18:29:27

2

System.Web.Mvc.CompareAttribute已被弃用。

我能够修改这样的工作:

[Required] 
    [DataType(DataType.Password)] 
    [Display(Name = "Confirm password")] 
    [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 
    public string ConfirmPassword { get; set; } 
相关问题