Copied to clipboard

Flag this post as spam?

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


  • Babajide 26 posts 46 karma points
    Jul 13, 2012 @ 22:17
    Babajide
    0

    Get an image's url and name with Razor

    I currently cannot get my .cshtml code to pull my image's url and name at the moment at the moment. Here it is:

     

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @if (Model.HasProperty("image"&Model.Image != 0{
      <p>Advanced<br />
       @{
          var image @Model.Media("image");
        }
        <img src='@image.Image' alt='@image.Name' />
      </p>
    else {
      <p>
        This page doesn't contain a MediaPicker property with the alias of 'RelatedMedia
        or No image is selected on this page
      </p>
    }

  • Brendan Rice 538 posts 1102 karma points
    Jul 16, 2012 @ 00:19
    Brendan Rice
    0

    I use the following helper method, you should be able to take the relevant code out of it:

    @helper renderImage(dynamic model, string nodeName, string cssClass)
        {
        if (model.GetPropertyValue(nodeName) != null && model.GetPropertyValue(nodeName) != string.Empty)
        {
            var mediaItem = model.MediaById(model.GetPropertyValue(nodeName));         @:<img src="@mediaItem.Url" alt="@mediaItem.Name" class="@cssClass" >     } }

    Hope this helps

Please Sign in or register to post replies

Write your reply to:

Draft