Copied to clipboard

Flag this post as spam?

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


  • BEWD 89 posts 301 karma points
    Feb 13, 2016 @ 12:40
    BEWD
    0

    Image not showing in Partial View

    Hi All

    I am having a bit of a problem with displaying an image that has been selected with a media picker through a Partial View.

    I have a pictureSectionImage and the Partial View code is as follows

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <div class="row">
        @foreach (var childPage in CurrentPage.pictureSections.Split(','))
        {
            var page = Umbraco.Content(childPage);
                <div class="col-sm-3">
                     <div class="work wow fadeInUp">
                    @if(CurrentPage.HasValue("pictureSectionImage"))
                        {
                            <img src="@Umbraco.Media(CurrentPage.pictureSectionImage).Url" />
                        }
                        <h3>@page.Name</h3>
                        <p>@page.pictureSectionText</p>
                    </div>
                </div>
        }
    

    It doesn't error and it displays the Page Name and pictureSelectionText fine, but the Image doesn't display even though it has been selected on the page.

    Any Ideas what I am doing wrong?

    Thanks

    Ben

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Feb 13, 2016 @ 12:50
    Jeavon Leopold
    100

    Hi Ben,

    I think you have mixed up page and CurrentPage a bit, I think what you need is this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <div class="row">
        @foreach (var childPage in CurrentPage.pictureSections.Split(','))
        {
            var page = Umbraco.Content(childPage);
                <div class="col-sm-3">
                     <div class="work wow fadeInUp">
                    @if(page.HasValue("pictureSectionImage"))
                        {
                            <img src="@Umbraco.Media(page.pictureSectionImage).Url" />
                        }
                        <h3>@page.Name</h3>
                        <p>@page.pictureSectionText</p>
                    </div>
                </div>
        }
    

    Jeavon

  • BEWD 89 posts 301 karma points
    Feb 13, 2016 @ 12:58
    BEWD
    0

    Of course, that's obvious now I have seen it. Thanks mate, been looking at that for a couple of hours and got myself in a muddle.

    Cheers

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Feb 13, 2016 @ 13:01
    Jeavon Leopold
    0

    Fab!

Please Sign in or register to post replies

Write your reply to:

Draft