Copied to clipboard

Flag this post as spam?

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


  • Caglar 23 posts 94 karma points
    Mar 22, 2021 @ 14:04
    Caglar
    0

    How can I get carousel on page?

    Hi all,

    I want to create a carousel, firstly I create a nested content then I added it on my homepage but when I called, it's not working.

    @{
          string carouselId = "mainCarousel";
          IEnumerable<IPublishedContent> carousel = Model.Value<IEnumerable<IPublishedContent>>(carouselId); }
    

    I got error like this object reference not set to an instance of an object. I tried many things but I failed to reach on solve. Btw I'm using v8.1.12.

    enter image description here

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 22, 2021 @ 15:32
    Alex Skrypnyk
    0

    Hi Caglar

    You have to use IPublishedElement instead of IPublishedContent like this:

    @{
          string carouselId = "mainCarousel";
          IEnumerable<IPublishedElement> carousel = Model.Value<IEnumerable<IPublishedElement>>(carouselId); }
    

    If you have single element nested content then like this:

    IPublishedElement carousel = Model.Value<IPublishedElement>("mainCarousel");
    

    All information needed for working with nested content you can find here - https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Nested-Content/

    Thanks,

    Alex

  • Caglar 23 posts 94 karma points
    Mar 22, 2021 @ 15:58
    Caglar
    0

    Hi Alex,

    I got same error.

    enter image description here

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 22, 2021 @ 16:07
    Alex Skrypnyk
    0

    and what about IEnumerable<IPublishedElement>

  • Caglar 23 posts 94 karma points
    Mar 22, 2021 @ 16:57
    Caglar
    0

    It doesn't work . I really don't know why I'm getting this error.

    My nested content;

    enter image description here

    Then I added this property on my home document type like as;

    enter image description here

    After, I filled with data in content menu and I clicked save&publish. After I called all this process on my partial view.

  • Caglar 23 posts 94 karma points
    Mar 23, 2021 @ 11:00
    Caglar
    1

    I fixed this problem with this code;

    var page = Umbraco.Content(Guid.Parse("eea1803b-f093-42f6-8483-b27df3323c2d"));
    var carousel = page.Value<IEnumerable<IPublishedElement>>("mainCarousel");
    
Please Sign in or register to post replies

Write your reply to:

Draft