执行条件验证
本文关键字:验证 条件 执行 | 更新日期: 2023-09-27 18:17:27
是否可以使用服务器端验证帮助程序有条件地验证字段?
例如
public partial class SomeEntity
{
public bool Chargeable { get; set; }
[RegularExpression(@"'d{8,8}", ErrorMessage = "should have alpha numeric characters.")]
public string CaseNumber { get; set; }
}
要求:当且仅当"可收费"为真时,案例编号是必需的。
我可以做:
[RegularExpression(@"'d{8,8}", ErrorMessage = "should have alpha numeric characters."), Required]
public string CaseNumber { get; set; }
但是,Required(if(Chargeable))
是我需要的...
让你的 SomeEntity 类实现 IValidatableObject 接口。