Copied to clipboard

Flag this post as spam?

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


  • Mike Ash 5 posts 95 karma points
    Feb 12, 2018 @ 08:50
    Mike Ash
    0

    Media picker returning null

    Hey folks,

    I'm new to Umbraco and tried to find my answer by browsing the forum but no luck so sorry if it's a duplicate question ...

    So my issue is that i've uploaded some pictures to my Media folder ( both root and sub-folders) but now when I want to access them in my view , they come as null aka no pictures ..

    I've tried different ways like :

     var test = Model.Content.GetPropertyValue<IPublishedContent>("newsImage");
    

    or

    var mediaId = Model.Content.GetPropertyValue<string>("newsImage");
    

    still it comes null. If i hardcode the id , It'll return my picture but I want to do it dynamically .. any tips ?

    cheers

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Feb 12, 2018 @ 11:27
    Anders Bjerner
    0

    Hi Mike,

    As you're trying to get the image from a property on a content item, I'm assuming this content item has a media/image picker. What type is that picker?

    If you're using the default media picker, I think the value type will be IEnumerable<IPublishedContent> (a list of images) rather than just IPublishedContent:

    var test = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("newsImage");
    

    Alternatively you can write out the type of the property value:

    object test = Model.Content.GetPropertyValue("newsImage");
    
    string type = test == null ? "NULL" : test.GetType() + "";
    

    type will either contain the value type, or NULL, but then something else is probably wrong.

  • Mike Ash 5 posts 95 karma points
    Feb 12, 2018 @ 13:37
    Mike Ash
    0

    Hey Anders,

    I guess I made myself a bit of inception here ... I'm trying to access the child picture on the parent view which will (obviously) return null. Problem is that I've changed the "Alias" to see if I can access the child but not luck yet.

    but on parent lvl this piece of code works just fine:

    Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("newsImage");
    

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft