Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created January 31, 2012 11:05
Show Gist options
  • Save warrenbuckley/1709929 to your computer and use it in GitHub Desktop.
Save warrenbuckley/1709929 to your computer and use it in GitHub Desktop.
Umbraco V5 Example - Media Upload Property
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@{
//Output an image from an upload property on current doctype
//Property alias of upload field
var uploadPropAlias = String.IsNullOrEmpty(Model.MacroParameters.uploadPropAlias) ? "myUploadPropertyAlias" : Model.MacroParameters.uploadPropAlias;
//Check if Value is not an empty HiveId
if (DynamicModel[uploadPropAlias].Value != HiveId.Empty.ToString())
{
//Get the image URL
//The HiveID of the currentpage
//Then the string property alias of the upload property
var imageURL = Umbraco.GetMediaUrl(DynamicModel.Id, uploadPropAlias);
<img src="@imageURL" alt="@DynamicModel.Name" />
}
else
{
<p>No Media present</p>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment