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 19 posts 160 karma points notactivated
    1 week ago
    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 261 posts 1003 karma points
    1 week ago
    Yakov Lebski
    0

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

    var val = Model.Value<IPublishedContent>("logo");
    
  • Kristian Overgaard 19 posts 160 karma points notactivated
    1 week ago
    Kristian Overgaard
    0

    Tested with

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

    and the result is still that val is null.

  • Dmitriy 138 posts 513 karma points
    1 week ago
    Dmitriy
    0

    Probably, problem is here:

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

    Check, if node is not null

  • Stuart Paterson 26 posts 146 karma points
    1 week ago
    Stuart Paterson
    0

    Hey,

    You could try -

    Model.Content.GetPropertyValue<IPublishedContent>("propertyName").Url
    
  • Kristian Overgaard 19 posts 160 karma points notactivated
    1 week ago
    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.

Please Sign in or register to post replies

Write your reply to:

Draft