Copied to clipboard

Flag this post as spam?

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


  • David Gregory 82 posts 208 karma points
    Mar 09, 2023 @ 13:28
    David Gregory
    0

    Umbraco 10.1.0

    Am I missing something simple here? The first if doesn't work but the second one does on this textBox property.

            @if (Model.HasValue(Model.WelcomeBoxTitle))
            {
                <h1>@Model.WelcomeBoxTitle (1)</h1>
            }
    
            @if (Model.HasValue("welcomeBoxTitle"))
            {
                <h1>@Model.WelcomeBoxTitle (2)</h1>
            }
    
  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 09, 2023 @ 13:43
    Huw Reddick
    0

    the second one is correct since the HasValue is to check if the property exists on the IPublishedContent and expects the property alias

  • David Gregory 82 posts 208 karma points
    Mar 09, 2023 @ 14:30
    David Gregory
    0

    Ah I see.

    Is there a way then to check if a property has content using the models builder version?

  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 09, 2023 @ 14:37
    Huw Reddick
    0

    HasValue will return false if the property itself is empty.

  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 09, 2023 @ 14:38
    Huw Reddick
    0

    sorry for confusion, my first comment was not 100% accurate.

  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 09, 2023 @ 14:44
    Huw Reddick
    0

    so @if (Model.HasValue("welcomeBoxTitle")) will be false if the property does not exist or is empty

  • David Gregory 82 posts 208 karma points
    Mar 09, 2023 @ 14:49
    David Gregory
    0

    Yes, that one works for me, but this one always returns false regardless i.e if there is content in the property or not.

    @if (Model.HasValue(Model.WelcomeBoxTitle))
            {
                <h1>@Model.WelcomeBoxTitle (1)</h1>
            }
    
  • Huw Reddick 1702 posts 5999 karma points MVP c-trib
    Mar 09, 2023 @ 15:04
    Huw Reddick
    1

    That is because Model.WelcomeBoxTitle is not the property alias, and hasvalue requires the property alias

Please Sign in or register to post replies

Write your reply to:

Draft