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 15, 2013 @ 01:19
    Keith Jackson
    0

    Getting a Media Url in Backend API Code (U4.11)

    I am trying to refactor a razor script call into a stringly typed model. Here's the model...

    using Ministry.Ministryweb.Models;

    namespace Ministry.Ministryweb.ViewModels
    {
    /// <summary>
    /// A model for the tem member card partial view.
    /// </summary>
    public class TeamMemberCardViewModel : MinistrywebBaseViewModel<TeamMember>
    {
    public TeamMemberCardViewModel(dynamic content)
    {
    InnerObject = new TeamMember(content);
    }

    public string JobTitle { get { return InnerObject.JobTitle; } }
    public string Email { get { return InnerObject.Email; } }
    public string Mobile { get { return InnerObject.Mobile; } }
    public int AvatarId { get { return InnerObject.AvatarNodeId; } }
    }
    }

    And the razor script is using it thusly...

    @inherits MinistrywebViewPage<TeamMemberCardViewModel>

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

    I would, ideally, like to move this bit of code...

    @Umbraco.Media(Model.AvatarId).umbracoFile

    ...into the model so, rather than exposing the ID, the model just exposes the URL. How can I get access to the umbracoFile property (The Media URL) without the UmbracoHelper?

Please Sign in or register to post replies

Write your reply to:

Draft