Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • wschwarte 44 posts 73 karma points
    Sep 03, 2014 @ 15:50
    wschwarte
    0

    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!
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 03, 2014 @ 15:53
    Jeavon Leopold
    1

    Try only @if(CurrentPage.showItem) for true or @if(!CurrentPage.showItem) for false

  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 03, 2014 @ 15:57
    Sören Deger
    0

    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

  • wschwarte 44 posts 73 karma points
    Sep 03, 2014 @ 16:02
    wschwarte
    0

    Oh ok. It seems: @if(CurrentPage.showItem) works! 

    Umbraco.TV told me to use getProperty for custom fields? Is this not true then?

     

     


  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 03, 2014 @ 16:13
    Jeavon Leopold
    0

    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)

Please Sign in or register to post replies

Write your reply to:

Draft