我正在尝试使用MVC Foolproof Validation工具包来强制字段具有值,如果早期状态字段已达到某个值...
“状态”字段类型是具有已定义int
值的ENum。
public enum RequestStatusENum { New = 10,
Processing = 20,
Rejected = 30,
Withdrawn = 40,
Confirmed = 50,
Cancelling = 60,
Cancelled = 70 }
状态达到Confirmed
后,我需要确保ConfirmationNumber
字段具有值
public RequestStatusENum Status { get; set; }
[Display(Name = "Confirmation Number")]
[RequiredIf("Status", Operator.EqualTo,
RequestStatusENum.Confirmed, ErrorMessage = "Confirmation Number required")]
public string ConfirmationNumber { get; set; }
使用上述设置,它可以正常工作并验证该字段是否有数据,但是,如果我更改为以下内容,则不会进行验证。
[RequiredIf("Status", Operator.GreaterThanOrEqualTo,
RequestStatusENum.Confirmed, ErrorMessage = "Confirmation Number required")]
或者
[RequiredIf("Status", Operator.GreaterThanOrEqualTo,
(int)RequestStatusENum.Confirmed, ErrorMessage = "Confirmation Number required")]
我看过this SO question虽然它很相似,但并不是明确的EqualsTo
比较,而不是GreaterThanOrEqualTo