Using DataAnnotations to compare two model properties
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How would I go about writing a custom ValidationAttribute that compares two fields? This is the common "enter password", "confirm password" scenario. I need to be sure the two fields are equal and to keep things consistent, I want to implement the validation via DataAnnotations. So in pseudo-code, I'm looking for a way to implement something like the following: public class SignUpModel { [ Required ] [ Display ( Name = "Password" )] public string Password { get ; set ; } [ Required ] [ Display ( Name = "Re-type Password" )] [