Copied to clipboard

Flag this post as spam?

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


  • Jonas Thierry 17 posts 98 karma points notactivated
    Mar 11, 2019 @ 08:26
    Jonas Thierry
    0

    Nested content is empty

    Hi I have a nested content called "footers" on my "Home node". If retrieve the "footers" by:

    var stamdata = Model.AncestorsOrSelf("home").First();
    

    and loop them by;

    var listofFooters = stamdata.Value<IEnumerable<IPublishedContent>>("Footers");
    

    i get a null

    however in my Visual debug it says: count2 and i can view the content.

    I can also get all the other values from "Home".

    My page declaration is:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    

    This worked in Umbraco 7xxx but not in Umbraco 8. Do i really need to supply the Home model to my footer?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 11, 2019 @ 12:21
    Alex Skrypnyk
    0

    Hi Jonas

    Can you check that property alias is exactly "Footers"? It should be exactly like in Umbraco and it's case sensitive.

    Thanks,

    Alex

  • Jonas Thierry 17 posts 98 karma points notactivated
    Mar 11, 2019 @ 12:50
    Jonas Thierry
    0

    Sure, here goes.... I have changed it back and forth when debugging so thats why it is in capital letters :-)

    enter image description here

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 11, 2019 @ 18:45
    Alex Skrypnyk
    0

    thanks, Jonas, looks right

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Mar 11, 2019 @ 18:47
    Alex Skrypnyk
    0

    Jonas, can you show the content section now? How many items are in nested content property?

    Is it one or few ones?

  • Jonas Thierry 17 posts 98 karma points notactivated
    Mar 12, 2019 @ 12:01
    Jonas Thierry
    0

    Hi Alex,

    I have 2 items right now:

    enter image description here

  • Michael Nielsen 155 posts 812 karma points
    Mar 12, 2019 @ 14:44
    Michael Nielsen
    101

    If Home is your top node, and you're using ModelsBuilder (which I strongly recommend), then you could do this

    var home = Model.Root() as Home;
    
    if(home.Footers != null & home.Footers.Any()){
       foreach (var footer in home.Footers)
       {
           @footer.Name
       }
    }
    
  • Jonas Thierry 17 posts 98 karma points notactivated
    Mar 12, 2019 @ 14:49
    Jonas Thierry
    1

    Thank you Michael

    I am using Modelsbuilder and now it works. :-)

  • Guido Adam 21 posts 65 karma points
    Sep 25, 2019 @ 20:51
    Guido Adam
    0

    Hi Jonas,

    If anyone's curious why it didn't work in the first place: nested content returns IPublishedElement in v8.

    stamdata.Value<IEnumerable<IPublishedElement>>("Footers")
    

    would have worked.

    Cheers!

    Guido

  • Henrik Vincent 122 posts 616 karma points
    Jan 26, 2021 @ 19:41
    Henrik Vincent
    0

    Brilliant!

Please Sign in or register to post replies

Write your reply to:

Draft