Copied to clipboard

Flag this post as spam?

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


  • Sam 79 posts 426 karma points
    Jul 02, 2021 @ 15:48
    Sam
    0

    multinode tree picker - iEnumerable IpublishedContent returning null

    Hello All,

    I am having trouble with the Multimode Tree Picker. The value always returns null despite the value being defined in Backoffice.

    Here is the code.

     @{var bannerLink = Model.Value<IEnumerable<IPublishedContent>>("linkToContent");}
    
                @if(bannerLink != null){
                    foreach (var link in bannerLink){
                       <a href="@link.Url">Learn More</a>
                    }
               }
    

    My result is the link is not rendering because of the condition if bannerLink !=null. If I remove the condition I get an error.

    enter image description here

    it just seems like IEnumerableI PublishedContent is not returning any value.

    Thanks in advance.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 03, 2021 @ 15:31
    Marc Goodson
    0

    Hi Sam

    A couple of things to check.,,

    Where is the LinkToContent property defined?

    is it on a page? eg does your homepage doctype have a LinkToContent property of Multi Node Tree Picker type?

    or

    do you have a NestedContent property, that allows for multiple Banners, and on each Banner there is a LinkToContent property?

    I ask only as it's really common to use model.Value within a foreach loop, accidentally referring to the page model, rather than the model being looped, eg banner.Value<IEnumerable<IPublishedContent>>("linkToContent")

    Sure you've checked the alias of the property is linkToContent it is case sensitive, been caught out by LinkToContent or linktoContent in this kind of frustrating scenario!

    Should the underlying property editor for linkToContent be a MultiUrlPicker?

    in which case:

    @{var bannerLink = Model.Value<IEnumerable<Link>>("linkToContent");}
    

    would be the way...

    also if you have multiple things picked here - won't the code result in multiple links called 'learn more' (but that's a future thing... getting it to work is first priority!)

    regards

    Marc

  • Sam 79 posts 426 karma points
    Jul 12, 2021 @ 11:05
    Sam
    0

    Hi Marc,

    Sorry for the late response... I took a Vacation.

    • The linkToContent property is part of the home page node, and is not within a foreach loop where the var might be item

    • I have checked the case and spelling of the property a few hundred times.

    • I can try to change the property editor to use multi URL picker, but I am having this issue with another property that does need more than just the link to content.

    • I have limited the Property to allow the customer to pick a maximum of 1 value to keep the user from selecting multiple.

    Something else to note... when I just place the property in the template as if it were a standard text field, I get the following value.

    Umbraco.Web.PublishedModels.AboutPageWithHighlights

    SO I see that there is some sort of value stored. and it is listing the document type at the end of it. As soon as I plug it in to the condition and the -Ienumerable-IPublishedContent-- it acts like there is no value.

    Thanks for the help.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 12, 2021 @ 20:37
    Marc Goodson
    100

    Hi Sam

    hope you had a good holiday

    quick thought, if you've restricted the picker to 1 item is it just an IPublishedContent item?

    eg

     @{var bannerLink = Model.Value<IPublishedContent>("linkToContent");}
    

    regards

    Marc

  • Sam 79 posts 426 karma points
    Jul 13, 2021 @ 11:45
    Sam
    0

    Thanks Marc. That did the trick, and it seems so obvious thinking about it. Here is what I ended up with.

    @{var bannerLink = Model.Value<IPublishedContent>("linkToContent");}
    
                @if(bannerLink != null){
    
                       <a href="@bannerLink.Url">Learn More</a>
    
               }
    
  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 13, 2021 @ 13:16
    Marc Goodson
    0

    Looks good, sorry I didn't think it first!

Please Sign in or register to post replies

Write your reply to:

Draft