0
仅当第三个字段具有特定值时,才需要验证两个字段。 在这个代码snipper我想使用不存在的CheckIf属性。 仅当其他属性具有特定值时才可以验证字段?企业库验证块 - 将条件验证为另一个属性值
public string CustomerType { get; set; } // P=Private B=Business
[NotNullValidator(MessageTemplate = "You must specify the property 'Name'", CheckIf = "CustomerType=='P'")]
public string PrivateName { get; set; }
[NotNullValidator(MessageTemplate = "You must specify the property 'Name'", CheckIf = "CustomerType=='B'")]
public string BusinessName { get; set; }
谢谢!
我的情况与第二种情况类似。当客户类型为“B”= Business时,“私人名称”必须是法定的名称,“公司名称”是公司的名称。我已经使用SefValidation,但我认为为了代码的可读性,将验证与属性值相关联的属性将会很有用。谢谢! – 2010-09-21 13:17:15