This code displays an image whether the box is checked or not. If i check the box. The image is still displayed. If the box is unchecked, the image is displayed.
Am i doing something wrong here?
Its an umbraco six build that I am working on. Cheers.
HasValue will be true if the property is contained in the data. Checking HasValue first will stop a null error if the property does not exist in the node you are looking at.
Something like:
@if(Model.HasValue("myTrueFalseCheckBox") && Model.myTrueFalseCheckBox == 1) // i'm not actually sure if it is equal to 1 when true
might be what you're looking for. Not actually given you the answer but hopefully explained why it is always showing the picture.
True/False Umbraco 6
Hello everyone,
I am having an issue with a piece of code.
@if(Model.HasValue("myTrueFalseCheckBox")
{
<img src="url here" alt="alt">
}
This code displays an image whether the box is checked or not. If i check the box. The image is still displayed. If the box is unchecked, the image is displayed.
Am i doing something wrong here?
Its an umbraco six build that I am working on. Cheers.
James.
Hi James
I think you should try writing your if statement like this
@if(!String.IsNullOrEmpty(Model.myTrueFalseCheckBox)){ //image code }
See the example here http://odetocode.com/blogs/scott/archive/2011/06/28/a-better-razor-isnullorempty-statement.aspx
Hope this helps.
/Jan
I appear to have fixed it :
@if(Model.myTrueFalseCheckBox)
{
Do Something
}
Thanks anyway.
Cheers
James.
HasValue will be true if the property is contained in the data. Checking HasValue first will stop a null error if the property does not exist in the node you are looking at.
Something like:
@if(Model.HasValue("myTrueFalseCheckBox") && Model.myTrueFalseCheckBox == 1) // i'm not actually sure if it is equal to 1 when true
might be what you're looking for. Not actually given you the answer but hopefully explained why it is always showing the picture.
because the property is a true or false.. the property will always have a value.. you need to test on what the actual value is
if (Model.GetProperty("myTrueFalseCheckBox").Value ){ true}else {false;}
is working on a reply...