0
votes

I am new to Umbraco and I'm trying to display an Image by using a document type, embedding the image into a template.

The document typ is called Image with an alias named Image, I have used the Media Picker document type.

I have the following line of code but it doesn't seem to be showing the image.

Can anyone help?

<img src="@Umbraco.Field("image")" alt=""/>
2
Thanks both very useful indeed! I cant seem to find any reference guides for this type of stuff, do you know where I can find anything?Dave Kane
24 days , there's umbraco community ... you just need to searchChaitanya Gadkari
@DaveKane please close your questions and please read SO guidelines.Morten OC

2 Answers

4
votes

The image field just contains a reference to the ID of the image, not the object itself. To display the image, do something like:

var image = Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("image"));
if (image != null)
{
    <img src="@image.GetPropertyValue("umbracoFile")" alt=""/>
}

Basically, what we do is use the Umbraco helper to instantiate an instance of a media item using the id in the image field, and then get the "umbracoFile" property of that media item, which contains the path to the image!

1
votes

Tim's solution will work, but I think its a bit easier just to write:

<img src="@Umbraco.Media(CurrentPage.Image).Url" alt=""/>