Copied to clipboard

Flag this post as spam?

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


  • Kristian Overgaard 22 posts 185 karma points notactivated
    Dec 03, 2019 @ 08:19
    Kristian Overgaard
    0

    Mediapicker property returns null

    I'm trying to retrieve the image of a media picker proeprty on a simple umbraco page, but the property always returns null. I've saved and published the page, and the value shows in backoffice.

    I've found similar questions, but the answers to those was to get the typed content and use value

    Here's some examples of how i try to retrieve the property value:

    @{
    Layout = "~/Views/Shared/_Layout.cshtml";
    var logourl = Model.Logo;//null
    
    var node = (DefaultPage)Umbraco.Content(Model.Id);
    var val = node.Value<IPublishedContent>("logo");//null
    
    var v = Model.HasProperty("logo");//true
    }
    

    Retrieving values from Title and Theme works, so I assume i have the right Model instance.

    enter image description here

  • Yakov Lebski 591 posts 2346 karma points
    Dec 05, 2019 @ 02:58
    Yakov Lebski
    0

    I think it should be like this (in case of Media Picker)

    var val = Model.Value<IPublishedContent>("logo");
    
  • Kristian Overgaard 22 posts 185 karma points notactivated
    Dec 05, 2019 @ 08:02
    Kristian Overgaard
    0

    Tested with

    var val = Model.Value<IPublishedContent>("logo");
    

    and the result is still that val is null.

  • Dmitriy 168 posts 588 karma points
    Dec 05, 2019 @ 08:06
    Dmitriy
    0

    Probably, problem is here:

    var node = (DefaultPage)Umbraco.Content(Model.Id);
    

    Check, if node is not null

  • Stuart Paterson 58 posts 229 karma points
    Dec 05, 2019 @ 08:33
    Stuart Paterson
    0

    Hey,

    You could try -

    Model.Content.GetPropertyValue<IPublishedContent>("propertyName").Url
    
  • Kristian Overgaard 22 posts 185 karma points notactivated
    Dec 05, 2019 @ 09:00
    Kristian Overgaard
    100

    I looked in the DB and confirmed there was a value for logo in the textvalue field: umb://media/75b82e019752477e826ce3426abb286a

    the node had value.

    I tried creating a new site from the same doctype, and adding the image again, and put in a title, and that works fine.

    The specific instance must be broken, but i can't figure where or why, since the doctype itself seems to work fine. I'm just going to delete the corrupt instance of the doctype, and work with the one that works, and see if the issue reappears.

  • Lars Lindstrøm 2 posts 32 karma points
    Nov 06, 2023 @ 16:55
    Lars Lindstrøm
    0

    I'm experiencing similar problems and have identified my issue being related to "Vary by culture". It seems of a property is not "vary by culture" enabled, it returns null. In most use cases when using Media Picker there will not be differences between culture.

    Was your case also a multi culture project?

Please Sign in or register to post replies

Write your reply to:

Draft