0

I have 4 checkboxes in my form and want user to select at least one of the checkbox when form is submitted.

I am using ExpressiveAnnotations.Attributes; reference as we use this in other part of project but it doesn't seems to be working for checkboxes.

I have 4 checkboxes lets say they are A, B, C, D and I have declared checkbox D as:

[Display(Name = "D Name")]
[AssertThat("(A == false) && (B == false) && (C == false) && (D== false)", ErrorMessage = "Required")]
public bool D { get; set; }

If I change 'AssertThat' to 'RequiredIf' - then it errors that A,B,C,D need to be Nullable

When I submit the form, all the other validations on the form works except this one. Once submitted, I can see the value of A,B,C,D are false.

I have looked into custom validation but can't seem to find what I am looking for.

Has anyone else has encountered this issue? Any help will be appreciated

Thanks,

tried looking into custom validation but no luck.

1 Answer 1

0

I was thinking wrong about AssertThat

i changed my AsertThat to:

[AssertThat("(A == true) || (B == true) || (C == true) || (D== true)", ErrorMessage = "Required")]

and thats working as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.