Cannot Get The Multinode Treepicker to work

Hi,

I am having problems with the multinode tree picker in umbraco 13

Whatever I try i get an error.

I am using the following line to get the treepicker contents…
var treepicker = Model.Content.Value(“myTreePicker”);

When I check what is returned it is coming back with this….
System.Collections.Generic.List\1[Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent]`

I am assuming it is bringing back the treepicker list correctly.

I am then using the following code to pick up each item in the list…

foreach (var item in treepicker)
{
    <p>@item.Name</p>
}

But I get an error.

Can anyone help please ?

Thanks

Docs here.. as the contentPicker is now a MNTP…
Content Picker | CMS | Umbraco Documentation

So with your example of var treepicker = Model.Content.Value(“myTreePicker”);

something like…

Without Models Builder

@{
    var typedContentPicker = Model.Content.Value<IEnumerable<IPublishedContent>>("myTreePicker");
    if (typedContentPicker != null) {
        foreach (var item in typedContentPicker)
        {
            <p>@item.Name</p>
        }
}

With Models Builder

@{
    var typedContentPicker = Model.Content.MyTreePicker;
    foreach (var item in typedContentPicker)
    {
        <p>@item.Name</p>
    }
}

I think I have worked it out.

Instead of using…
var treepicker = Model.Content.Value(“myTreePicker”);

I am now using…
var treepicker = Model.Content.Value<IEnumerable>(“myTreePicker”);

And it now works. I just need to work out how to pick up unpublished items in the list

EDIT : Somebody beat me to it , thanks

1 Like

You mention pick up unpublished items in the list as this query is against the publishedContentCache you simply can’t.. that’s the idea unpublished not available to the frontend. :slight_smile:

You could use the ContentService, but that would hit the Database so expensive

You also can’t get them from the External Examine index as again by default that includes only published items…
But you could get from the Internal Examine Index, but again that’s really for the backoffice to use.

I wonder if you need to rethink your content strategy if you require unpublished items at the front end.. perhaps something as simple as as a toggle for shownInList or hiddenInList depending on the default (but I’d go for needing to toggle shownInList to stop human error and accidents of content appearing that isn’t required..) and not use published as the flag here?