简体   繁体   中英

Display images using umbraco razor syntax

I am very new to umbraco, can anyone help me out on how to make this using razor c# and macro?

Thanks in advance!

add a media picker property with alias of "image" to your document, call "MediaById" to convert that to image ID to a the URL.

Stick the below in your template:

<umbraco:Macro runat="server" language="cshtml">
    <img src="@Model.MediaById(Model.image).umbracoFile" alt=""/>
</umbraco:Macro>

see http://our.umbraco.org/forum/developers/razor/20872-How-do-I-show-an-Image

Welcome to umbraco, all you need is to create a dynamic media from the media picker on you page and in you razor macro you will get an id of the image then use that to create the image. Replace "yourImagePropertyAlias" with the alias of you image picker property.

if (!string.IsNullOrEmpty(Model.yourImagePropertyAlias.ToString()))
{
    dynamic mediaItem = Library.MediaById(Model.yourImagePropertyAlias);
    <img src="@mediaItem.umbracoFile" alt="@mediaItem.Name" />
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM