Copied to clipboard

Flag this post as spam?

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


  • Klaus Kunath 20 posts 119 karma points
    Mar 06, 2023 @ 10:07
    Klaus Kunath
    0

    Umbraco.Media(id) does not work in Umbraco 11

    Hello,

    i try to get the children of a media folder from Multimediapicker Paramenter in a Macro Partial View

    var folder = Model.GetParameterValue<int>("mediaFolder"); 
    

    this is correct, id is 1117, folder has 5 children

    var selection = Umbraco.Media(folder);
    

    this return always null

    Can anyone help?

  • Paul Griffiths 370 posts 1021 karma points
    Mar 06, 2023 @ 12:58
    Paul Griffiths
    0

    Hello!

    Not really up to speed with v11 just yet but to get the children of a media folder can you try using using the Children property of the media item object that represents the folder. Maybe something like:

    var folderId = Model.GetParameterValue<int>("mediaFolder");
    var folder = Umbraco.Media(folderId);
    
    if (folder != null)
    {
        var children = folder.Children();
    
       foreach (var child in children)
       {
            var imageUrl = child.Url;
            / / Do something with the imageUrl here
       }
    }
    

    *codes untested

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft