Copied to clipboard

Flag this post as spam?

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


  • Mark Watson 118 posts 384 karma points
    Feb 27, 2019 @ 03:16
    Mark Watson
    0

    Render image in partial

    We are new to Umbraco and seem not to be able to get the simple things able to work. We just want to display an image in a partial and can not get it to work.

    The code we are using is

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var selection = Model.Content.Site().FirstChild("caseHistoryPage").Children("")
                            .Where(x => x.IsVisible());
    }
    
    
        @foreach(var item in selection){
            <div class="row">
      <div class="col-sm-6 col-md-12">
        <div class="thumbnail">
    
    
      @{
        var typedMediaPickerSingle = item.GetPropertyValue<IPublishedContent>("caseHistoryMainImage");
    
        if (typedMediaPickerSingle != null )
        {
            <img src="@typedMediaPickerSingle.Url" />
        }
    
    }
    
    
        <div class="caption">
            <h3>@item.GetPropertyValue("caseHistoryItemHeading")</h3>
    <p><a href="#" class="btn btn-primary" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
          </div>
        </div>
      </div>
    </div>
        }
    

    What are we missing?

  • Tarik 196 posts 840 karma points c-trib
    Feb 27, 2019 @ 11:43
    Tarik
    100

    Mark, try the following code:

    @{
        var typedMediaPickerSingle = Umbraco.TypedMedia(@Umbraco.Field(item,"caseHistoryMainImage").ToString());
        if (typedMediaPickerSingle != null )
        {
            <img src="@typedMediaPickerSingle.Url" />
        }
    }
    

    Why, visit this.

Please Sign in or register to post replies

Write your reply to:

Draft