Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
How can i check a true/false custom propertyfield in a partial view. I now get an error message.
Line 100: Line 101: Line 102:@if(@CurrentPage.GetProperty("showItem") == true ) Line 103:{ Line 104: @:it was true!
Try only @if(CurrentPage.showItem) for true or @if(!CurrentPage.showItem) for false
@if(CurrentPage.showItem)
@if(!CurrentPage.showItem)
Hi,
you must convert your property value to bool
@if(CurrentPage.GetPropertyValue("showItem") == true)
or to string like this
@if(CurrentPage.GetProperty("showItem").ToString() == "1")
EDIT: Jeavon's solution is the easiest and best :-)
Sören
Oh ok. It seems: @if(CurrentPage.showItem) works!
Umbraco.TV told me to use getProperty for custom fields? Is this not true then?
There are 2 models, the dynamic one (CurrentPage) and the typed one (Model.Content)
For dynamic, you would do @if(CurrentPage.showItem) for typed you would do @if(Model.Content.GetPropertyValue<bool>("showItem"))
@if(Model.Content.GetPropertyValue<bool>("showItem"))
Dynamic is concise but typed brings intellisense (in Visual Studio)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor True/False in Partial View
How can i check a true/false custom propertyfield in a partial view. I now get an error message.
Operator '==' cannot be applied to operands of type 'object' and 'bool'
Line 100: Line 101: Line 102:@if(@CurrentPage.GetProperty("showItem") == true ) Line 103:{ Line 104: @:it was true!
Try only
@if(CurrentPage.showItem)
for true or@if(!CurrentPage.showItem)
for falseHi,
you must convert your property value to bool
or to string like this
EDIT: Jeavon's solution is the easiest and best :-)
Sören
Oh ok. It seems: @if(CurrentPage.showItem) works!
Umbraco.TV told me to use getProperty for custom fields? Is this not true then?
There are 2 models, the dynamic one (CurrentPage) and the typed one (Model.Content)
For dynamic, you would do
@if(CurrentPage.showItem)
for typed you would do@if(Model.Content.GetPropertyValue<bool>("showItem"))
Dynamic is concise but typed brings intellisense (in Visual Studio)
is working on a reply...