Copied to clipboard

Flag this post as spam?

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


  • Naveed Ali 157 posts 422 karma points
    Apr 02, 2018 @ 20:15
    Naveed Ali
    0

    Getting ID from media picker

    I have a media picker with multiple images in there.

    I have a surface controller. I want to get a list of the images from the property.

    I have tried many ways but cannot do this. The only way it works is if I type a media ID in like this:

     var logo = Umbraco.TypedMedia(1139);
    

    This is not obviously a good way as i have multiple ID's.

    I have tried this:

    var galleryPage = Umbraco.Content(1143);
    var images = galleryPage.TypedMedia(galleryPage.Content.GetPropertyValue("galleryImages"));
    

    but i get nothing

    can someone please point me in the right direction.

    Thanks

  • Søren Gregersen 355 posts 1468 karma points MVP 2x c-trib
    Apr 02, 2018 @ 20:47
    Søren Gregersen
    0

    What version of umbraco are you using? :)

    The latter versions have property value converters, where you can just ask for a list of publishedcontent like this:

    var images = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("galleryImages")
    

    with modelsbuilder it's even more simple:

    var images = Model.Content.GalleryImages;
    
  • Naveed Ali 157 posts 422 karma points
    Apr 02, 2018 @ 20:50
    Naveed Ali
    0

    Thanks for the reply.

    Yes but that is in the razor view isnt it?

    I am doing this in a surfacecontroller..would it also work in their..if so what would "Model" be in a Controller.

  • Søren Gregersen 355 posts 1468 karma points MVP 2x c-trib
    Apr 02, 2018 @ 20:58
    Søren Gregersen
    0

    that's just c# code.

    Of course you may not have a model with content, but as long as you have the content, you should be able to use one of the methods described :)

  • Naveed Ali 157 posts 422 karma points
    Jun 24, 2018 @ 15:53
    Naveed Ali
    0

    sorry been a while, had this project on hold. Just like to add the above solution does not work. Still looking for a solution will post if i find one. Thanks

  • Naveed Ali 157 posts 422 karma points
    Jun 24, 2018 @ 16:59
    Naveed Ali
    0

    For anybody else looking for a solution this thread is a good read:

    UID media urls

    There are a few good threads on how to convert the UID to a proper media url or get the whole media object via the UID.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies