Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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


  • David Hyslop 22 posts 155 karma points
    5 days ago
    David Hyslop
    0

    Get URL of Media Picker Image

    Hi

    If anyone could offer any help would be greatly appreciated. This one is driving me mad.

    I'm displaying some child pages in a template and have an image in the pages that I'd like to display and am strggling getting the Url of that image.

        @{
                    var navitem = CurrentPage.Children.Where("Visible");
    
    
                }
    
                @{foreach (var item in navitem)
    
                    {
                        <div class="col-xs-4">
                            <div class="news-item">
    
                                <h2> @item.pageTitle</h2>
                                <p> <i class="fa fa-calendar" aria-hidden="true">@item.UpdateDate.ToString("dd MMMM yyyy")</i><br /></p>
                                <p class="news-intro">
    
                                    @item.introText
    
                                </p>
    
                           <img src="@item.newsImage">
                            </div>
                        </div>
                    }
    
                }
    

    Its @item.newsImage where I'm just getting the ID. Does anyone know how to convert that to the URL.

    Thanks.

  • Alex Skrypnyk 3804 posts 13322 karma points mvp
    5 days ago
    Alex Skrypnyk
    100

    Hi David

    Use this code:

    <img src="@Umbraco.Media(item.newsImage).Url">
    

    Also be aware that dynamics isn't the best practice for using.

    Thanks,

    Alex

  • David Hyslop 22 posts 155 karma points
    4 days ago
    David Hyslop
    0

    Thanks Alex, little change but worked fine.

      @{int newsImageId = item.newsImage;
                                }
    
                                <img src="@Umbraco.Media(newsImageId).Url">
    
  • Alex Skrypnyk 3804 posts 13322 karma points mvp
    4 days ago
    Alex Skrypnyk
    0

    Glad to help you!

    Have a great evening!

Please Sign in or register to post replies

Write your reply to:

Draft