Skip to content
Erik W edited this page Mar 17, 2016 · 3 revisions

Media objects are treated just like regular Umbraco model objects, but need a special annotation to indicate that they are media items instead of documents. This is due to the way that Umbraco handles Media in its backend.

Media Mapping Example

First we need to create a baseline media object in Umbraco that we can map media items to. We have not included a default Media object because custom properties will almost always be added, and it is trivial to make your own.

Here is a sample Media POCO you would use to map Umbraco media items to:

[UmbracoMediaEntity(AutoMap = true)]
public class UmbracoImage
{
    [UmbracoProperty(Alias = "umbracoFile")]
    public string Url { get; set; }
    public string Alt { get; set; }
}

The UmbracoMediaEntity is the special dention that indicates this should map to a Media item and not a Document item.

Consider a simple blog post document in Umbraco:

Blog Post Document

Mapping to the image would be as simple as including the Image reference in your Blog post C# object.

[UmbracoEntity(AutoMap = true)]
public class BlogEntryViewModel
{
	public string Title { get; set; }
	public DateTime PostDate { get; set; }
	
	[UmbracoRichTextProperty]
	public string Content { get; set; }	
		
	public bool Featured { get; set; }
		
	public UmbracoImage Image { get; set; } //The image class referenced above
}
Other Vault Extensions:
Clone this wiki locally