Copied to clipboard

Flag this post as spam?

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


  • Nick 2 posts 72 karma points
    Jan 15, 2019 @ 22:43
    Nick
    0

    Display image from media library 7.13

    Hey gang, I'm new to umbraco, and really liking it so far, but this task is driving me batty. It really shouldn't be this hard, so I must be missing something easy.

    I'm using ver 7.13, and I'm just trying to display an image from the media library (using media picker 2) on my page in my partial view.

    Have tried a number of different things, all with zero results. here's what my partial looks like:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using senegence_um.web.Models
    <header>
    <div class="logo">
      @{
            string imageUrl = Model.Content.GetPropertyValue<IPublishedContent>("image").Url;
        }
    
        <img src="@imageUrl" />
    </div>
    

    This just produces a YSOD, stating that my object reference not set to an instance of an object.

    Here is a SS of my imagePicker doc type: enter image description here

    I've tried inserting both words (circled in red) into my partial view, and both produce the same results.

    So I'm stumped. Not sure why it's telling me it can't find the reference to the object.

    P.s., yes, I have published an image on my homepage, so there is content for it to find.

    Would appreciate any suggestions you all might have, as I'm sure it's just me doing something boneheaded and overlooking something possibly obvious. :)

  • Marc Goodson 2141 posts 14324 karma points MVP 8x c-trib
    Jan 18, 2019 @ 09:31
    Marc Goodson
    1

    Hi Nick

    It looks to be a problem converting your picked item to an IPublishedContent item, and calling .Url on a null object is throwing the Error message.

    It would be interesting to see if

    <h1>@Model.Content.GetPropertyValue("image")</h1>
    

    writes out the id of the picked media item or is empty somehow?

    If it is the id of the a media item, it would again be interesting to see if

    @{
    var pickedMediaId = Model.Content.GetPropertyValue<string>("image");
    var pickedMediaItem = Umbraco.TypedMedia(pickedMediaId);
    var hasMediaItem = pickedMediaItem!=null;
    }
    
    @if(hasMediaItem){
      <img src="@pickedMediaItem.Url" />
    }
    

    would display an image or not... (not saying 'this is the way to do it') but if it works would indicate problem is in the property value converter for the new media picker...

    regards

    Marc

  • Nick 2 posts 72 karma points
    Jan 18, 2019 @ 16:40
    Nick
    0

    Hi Marc,

    Awesome, I'll give that a try and report back with my findings. :)

Please Sign in or register to post replies

Write your reply to:

Draft