Copied to clipboard

Flag this post as spam?

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


  • ggesheva 14 posts 114 karma points
    16 days ago
    ggesheva
    0

    Rendering image from member's property media picker

    Hi there!

    After setting up coustom routing for members profile pages I want to display all the data they have as member properties.

    Some of those properties are Images selected from Media Pickers. memberProfile is from Umbraco.Core.Models.Member.

    @if (memberProfile.HasProperty("photo")) 
    { 
       var photo = memberProfile.GetValue<IPublishedContent>("photo"); 
       <img class="about-image" src="@photo.Url()" alt="@memberProfile.Name"> 
    }
    

    I made sure there is an image that's already picked but the variable photo is still being left out as a null. If I remove the <IPublishedContent> the variable gets the umb value.

    How could I solve this issue?

  • Thomas Kassos 43 posts 227 karma points
    15 days ago
    Thomas Kassos
    0

    Hi ggesheva, I am not sure what exactly is the issue but here are 3 things to try.

    First in case you are using a the MediaPicker2 with Multiple enabled, try something like this

      @if (memberProfile.HasProperty("photo")) 
    { 
       var photo = memberProfile.GetValue<IEnumerable<IPublishedContent>>("photo").FirstOrDefault(); 
       <img class="about-image" src="@photo.Url()" alt="@memberProfile.Name"> 
    }
    

    and if its the new MediaPicker3 try something like this

    Multiple enable:

      @if (memberProfile.HasProperty("photo")) 
    { 
       var photo = memberProfile.GetValue<IEnumerable<MediaWithCrops>>("photo").FirstOrDefault(); 
       <img class="about-image" src="@photo.Url()" alt="@memberProfile.Name"> 
    }
    

    Multiple disabled:

      @if (memberProfile.HasProperty("photo")) 
    { 
       var photo = memberProfile.GetValue<MediaWithCrops>("photo"); 
       <img class="about-image" src="@photo.Url()" alt="@memberProfile.Name"> 
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft