Copied to clipboard

Flag this post as spam?

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


  • Shawn Calvert 31 posts 196 karma points
    Jul 10, 2018 @ 22:56
    Shawn Calvert
    0

    Multinode Treepicker 2 in partial

    I'm guessing this is something super simple, but I've hit a dead end.

    I am trying to render a MultiNode Treepicker2 datatype in a partial to reuse on multiple pages throughout my site.

    If I have the properties in a in single document type, and only use it on that template, this works as expected:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @using Umbraco.Web.Models;
    
        @{
            var typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
            foreach (var item in typedMultiNodeTreePicker)
            {
                <p class="sidebar-ten-years-entry-title"><a href="@item.Url">@item.Name</a></p>
            }
         }
    

    but if I try to move those properties in a stand-alone content type to reuse in a partial across the site, this doesn't work:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @using Umbraco.Web
    @using Umbraco.Web.Models;
    
    @{
        var tenyears = Umbraco.TypedContent(1687).Children("tenYearsAgoThisWeek");
        var typedMultiNodeTreePicker = tenyears.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
        foreach (var item in typedMultiNodeTreePicker)
        {
    
        }
     }
    

    this gives the error: System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>' does not contain a definition for 'GetPropertyValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.GetPropertyValue<T>(Umbraco.Core.Models.IPublishedContent, string)' has some invalid arguments

    It seems like it should work, I'm misunderstanding something fundamental about how IPublishedContent works. Thank you

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jul 11, 2018 @ 05:13
    Søren Gregersen
    100

    Hi Shawn,

    You are trying to call a method that does not exist - tenyears is a list of children, not publishedcontent.

    You either need to iterate (foreach) the "tenyears"-list, or pick the first child

    @{
        var tenyears = Umbraco.TypedContent(1687).Children("tenYearsAgoThisWeek");
        foreach (var child in tenyears)
        {
            var typedMultiNodeTreePicker = child.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
            foreach (var item in typedMultiNodeTreePicker)
            {
                //render
            }
        }
    }
    
  • Shawn Calvert 31 posts 196 karma points
    Jul 11, 2018 @ 05:45
    Shawn Calvert
    0

    It worked - that totally makes sense - thank you very much for taking the time!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies