I have this model class:
public class Model
{
public string FirstProperty { get; set; }
public string SecondProperty { get; set; }
}
Validation should pass when:
- FirstProperty value is not empty and SecondProperty value is empty
- SecondProperty value is not empty and FirstProperty value is empty
- FirstProperty value is empty and SecondProperty value is empty
I tried this:
RuleFor(x => x.FirstProperty)
.NotEmpty()
.When(x => string.IsNullOrEmpty(x.SecondProperty)
RuleFor(x => x.SecondProperty)
.NotEmpty()
.When(x => string.IsNullOrEmpty(x.FirstProperty)
But how to applied also third requirement (Both properties could be empty) ?