2010-03-15 168 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; } 
相關問題