Copied to clipboard

Flag this post as spam?

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


  • k 139 posts 339 karma points
    Apr 23, 2018 @ 11:51
    k
    0

    Hello,

    I am using nested content and it works fine when I use the below :

    var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("myPropertyAlias");
    
    foreach(var item in items)
    {
        // Render your content, e.g. item.GetPropertyValue<string>("heading")
    }
    

    However when I try to get the values of a child node as below :

      foreach(var cat in CurrentPage.Children.Where("Visible"))
            {
                var items = cat.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("director");
                foreach(var item in items)
                    {
    
                        <h3>@item.GetPropertyValue("test")</h3>
    
                    }
            }
    

    I get nothing from "cat"

    Can someone please help me with the right syntax ? Please help me find what I am doing wrong.

    Thanks,

    Kusum

  • Alex Skrypnyk 4539 posts 16231 karma points MVP 2x admin
    Apr 23, 2018 @ 12:15
    Alex Skrypnyk
    0

    Hi

    Use this code:

    foreach(var cat in Umbraco.AssignedContentItem.Children.Where(x => x.IsVisible()))
    {
        var items = cat.GetPropertyValue<IEnumerable<IPublishedContent>>("director");
        foreach(var item in items)
        {
    
            <h3>@item.GetPropertyValue("test")</h3>
    
        }
    }
    
  • Alex Skrypnyk 4539 posts 16231 karma points MVP 2x admin
    Apr 24, 2018 @ 10:48
    Alex Skrypnyk
    0

    Hi K

    Did you solve the issue? Share with us, please.

    Thanks,

    Alex

  • k 139 posts 339 karma points
    Apr 24, 2018 @ 13:26
    k
    0

    Hello Alex,

    Sorry for late reply.

    I have used the above code but I am getting the below error ; enter image description here

  • Steve Morgan 956 posts 2965 karma points c-trib
    Apr 24, 2018 @ 15:23
    Steve Morgan
    100

    Hmmm.. you shouldn't need to null check but does this work?`

        @foreach(var cat in Model.Content.Children().Where(x => !x.GetPropertyValue<bool>("umbracoNaviHide")))
    {
        if (cat.HasValue("director"))
        {
            var items = cat.GetPropertyValue<IEnumerable<IPublishedContent>>("director");
            foreach (var item in items)
            {
    
                <h3>@(item.GetPropertyValue<string>("test"))</h3>
    
            }
        }
    }
    
  • k 139 posts 339 karma points
    Apr 26, 2018 @ 07:14
    k
    0

    Hi steven,

    Thanks a lot. Code working perfectly well. :)

    k

Please Sign in or register to post replies

Write your reply to:

Draft