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 183 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 376 posts 1468 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 183 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 586 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 34 posts 175 karma points
    Dec 05, 2019 @ 08:33
    Stuart Paterson
    0

    Hey,

    You could try -

    Model.Content.GetPropertyValue<IPublishedContent>("propertyName").Url
    
  • Kristian Overgaard 22 posts 183 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.

Please Sign in or register to post replies

Write your reply to:

Draft