Copied to clipboard

Flag this post as spam?

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

  • jonok 258 posts 474 karma points
    Mar 19, 2019 @ 19:17

    U8 - How to display the media URL from Media Picker property?

    I am trying to display the URL of a media item that has been selected from a media picker property. Any assistance would be greatly appreciated.

    I have a nested content datatype:

    var contentBlocks = Model.Value<IEnumerable<IPublishedElement>>("contentBlocks");

    and I am then trying to loop through these, and get a node from a content picker, and then get a media picker property named 'image' from this node:

    foreach(var item in contentBlocks){
        var contentBlock = item.GetProperty("block").Value<IPublishedElement>();
        var imageUrl = contentBlock.GetProperty("image").Value().Url;

    but I am having trouble retrieving the Url into the 'imageUrl' var. I am receiving the error "Cannot assign method group to an implicitly-typed variable", and I've tried a few different things but still can't get the Url property from the Image.

  • Paul Seal 399 posts 2160 karma points MVP 2x c-trib
    Mar 19, 2019 @ 22:43
    Paul Seal

    Hi Jonok

    This is how you do it in v8.

    var imageUrl = Model.Value<IPublishedContent>("imageAlias")?.Url ?? "";
  • jonok 258 posts 474 karma points
    Mar 20, 2019 @ 08:33

    One other thing Paul - what do the question marks do? Do they check if the property exists before attempting to get the URL?

  • Paul Seal 399 posts 2160 karma points MVP 2x c-trib
    Mar 20, 2019 @ 09:13
  • jonok 258 posts 474 karma points
    Mar 19, 2019 @ 22:53

    Thanks very much Paul. Not sure why I was using IPublishedElement (I think I saw it on some example code somewhere), but changing it to IPublishedContent has fixed it.

  • Søren Gregersen 320 posts 1319 karma points MVP c-trib
    Mar 20, 2019 @ 07:34
    Søren Gregersen

    An element does not have an url :-)

    It only lives as a property on a document, like nested content.

Please Sign in or register to post replies

Write your reply to: