Display div using an If statement, when a checkbox is 'checked'.
I am trying to show a div if a checkbox is checked. Before, ? 0 : 1 worked for me when I made a lambda expression. On this occasion, however, on an if statement, the div I wish to 'show/hide' based on the checkbox still shows, even when it is not checked.
I think the issue is more to do with the operators and their behaviour. Generally if you are using Or's and And's you need to wrap the groupings in parenthesis. If it was me, I'd restructure the if to be something more like this:
Display div using an If statement, when a checkbox is 'checked'.
I am trying to show a div if a checkbox is
checked
. Before,? 0 : 1
worked for me when I made a lambda expression. On this occasion, however, on anif
statement, the div I wish to 'show/hide' based on the checkbox still shows, even when it is not checked.I have also tried another code line I saw on Our:
On the above, I get the exception
Cannot apply operator "" to operands of type 'object' and 'bool'.
But with no luck. Any idea what I am doing wrong?
Thanks very much
-David
Hi David
If you only render the
@Model.Content.GetPropertyValue("ShowSignUpForm)
what does it then output? Does it output "True" or 0?If it does output "True" then please try writing your second if statement like
I hope this helps!
/Jan
Hi David,
Alternatively you can try:
This should now work as you are making the returned result strongly typed as a boolean, meaning you don't even need an == true comparison.
Do'h! I should have suggested that initially really - I must not have been fully awake earlier ;-)
/Jan
Hi David,
I think the issue is more to do with the operators and their behaviour. Generally if you are using Or's and And's you need to wrap the groupings in parenthesis. If it was me, I'd restructure the if to be something more like this:
What this is then doing is:
1) If the Name is equal to Biography or About, irrelevant of case
AND
2) If
ShowSignUpForm
is trueTHEN
Display Div with Test text.
Does that work for you?
Nik
is working on a reply...