Copied to clipboard

Flag this post as spam?

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


  • Thibaut Dupont 1 post 31 karma points
    Sep 14, 2021 @ 23:30
    Thibaut Dupont
    0

    Umbraco 9 : ModelsBuilder and typed model for children elements

    Hi,

    I'm working with Umbraco 9, rc3 for a new project of mine. And I can't find a way to make ModelsBuilder works for children elements in my main page.

    I have a Blog page, where I can use the typed model thanks to the @inherits directive on top of the View.

    However, when I try to typed manually my blogPosts, I need to provide a IPublishedValueFallback and I just can't make it works somehow. I tried passing null but it fails when a property is optional.

    Here is the kind of code I would like to make it work, based on what I've been doing in Umbraco 8:

    var blogposts = blogList.Children().Select(x => new Blogpost(x));

    Thanks in advance for any help.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Sep 15, 2021 @ 05:15
    Søren Gregersen
    101

    Hi,

    You could use blogList.Children().OfType<BlogPost>()

  • Thomas 319 posts 606 karma points c-trib
    Nov 17, 2021 @ 19:16
    Thomas
    0

    Hi

    I have something like this,

    But that don't work..

    NCmediaBox Mediabox = new NCmediaBox(Model, null);
        if (Mediabox.Picker != null)
        {
            Mediabox = new NCmediaBox(Mediabox.Picker, null);
        }
    

    Is there a better why to do it ?

Please Sign in or register to post replies

Write your reply to:

Draft