Copied to clipboard

Flag this post as spam?

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


  • Keith Jackson 183 posts 552 karma points
    Jan 14, 2013 @ 15:04
    Keith Jackson
    0

    Getting Media Url in Razor

    Hi all, I'm new to 4.11, after developing on U5 - How do I get the URL for media?

    I have an object which is a child of the current page and I'm trying to get the following to work...

     

                @foreach (var teamMember in CurrentPage.Children)
    {
    if (teamMember == null || teamMember.Hidden)
    {
    continue;
    }

    <div class="teamMember teamMemberLeft">
    <a href="@teamMember.Url"><img src="@Umbraco.Media(teamMember.Avatar)" alt ="@teamMember.Name" /></a>
    <h4><a href="@teamMember.Url">@teamMember.Name</a></h4>
    <p><strong>@teamMember.JobTitle</strong><br />
    <a href="mailto:@teamMember.Email">@teamMember.Email</a>
    @if (!String.IsNullOrWhiteSpace(teamMember.Mobile))
    {
    <br />
    @teamMember.Mobile
    }
    </p>
    </div>
    }

    This is returning the object name instead - 'Umbraco.Web.Models.DynamicPublishedContent', suggesting I'm missing a dynamic property to get the actual URL but what is it?

  • gary 385 posts 916 karma points
    Jan 14, 2013 @ 20:10
    gary
    100

    Hi Keith

    Had the same issues going from U5, so will try to help. Have always used the DAMP package, but I think something like this should work.

    dynamic d = @Umbraco.Media(teamMember.Avatar);

    <img [email protected] />

    This will hopefully point you in the right area

    Regards

Please Sign in or register to post replies

Write your reply to:

Draft