1

I am trying to use the MVC Foolproof Validation toolkit to enforce a field has a value if a earlier status field has reached a certain value...

The Status field type is an ENum with defined int values.

public enum RequestStatusENum { New = 10, 
                                Processing = 20,
                                Rejected = 30,
                                Withdrawn = 40,
                                Confirmed = 50,
                                Cancelling = 60,
                                Cancelled = 70 }

Once the status has reached Confirmed, I need to ensure that the ConfirmationNumber field has a value

public RequestStatusENum Status { get; set; }

[Display(Name = "Confirmation Number")]
[RequiredIf("Status", Operator.EqualTo,
    RequestStatusENum.Confirmed, ErrorMessage = "Confirmation Number required")]
public string ConfirmationNumber { get; set; }

With the above setting, it works fine and validates that the field has data, however, if I change to the following, no validation occurs.

[RequiredIf("Status", Operator.GreaterThanOrEqualTo,
    RequestStatusENum.Confirmed, ErrorMessage = "Confirmation Number required")]

or this

[RequiredIf("Status", Operator.GreaterThanOrEqualTo,
    (int)RequestStatusENum.Confirmed, ErrorMessage = "Confirmation Number required")]

I've looked at this SO question and whilst it is similar, it's not as that is an explicit EqualsTo comparison, not a GreaterThanOrEqualTo

Community
  • 1
  • 1
Chris Hammond
  • 2,064
  • 5
  • 27
  • 53

0 Answers0