Copied to clipboard

Flag this post as spam?

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


  • Christian A 24 posts 98 karma points c-trib
    Nov 22, 2017 @ 08:57
    Christian A
    0

    IMember GetValue<IPublishedContent> on Media Picker Property returns null

    I'm working on a site which has a members section. I have extended the standard member type with some custom properties, one of them being a Media Picker - Image Only for choosing picture. Inspecting the IMember object, the "picture" property contains the Udi of the Media Node, but GetValue< returns null.

    @{
      int totalRecords;
    
      var members = ApplicationContext.Current.Services.MemberService.GetAll(0, 500, out totalRecords);
    }
    
    <ul>
      @foreach (IMember member in members)
      {
        var picture = member.GetValue<IPublishedContent>("picture");
    
        <li>
            <div class="post_thumb">
                @if (picture != null)
                {
                    <img src="@picture.Url" class="avatar photo" />
                }
            </div>
            <div class="post_title">
                <strong>@member.GetValue<string>("name")</strong>
            </div>
        </li>
      }
    </ul>
    

    This work around solves it, but it's not a very nice solution compared to casting it right away:

    var pictureUdi = member.GetValue<Udi>("picture");
    if (pictureUdi != null)
        picture = Umbraco.TypedMedia(pictureUdi);
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies