Code sample

Display template for images when using EPiServer CMS and ASP.NET MVC

Given you have an URL property with a UI hint to indicate that the editor should select an image, like this:

public virtual Url TopImage { get; set; }

Then you can make it render as an image by placing a partial view in the /Views/DisplayTemplates folder named Image.cshtml with the following content:

@model EPiServer.Url
@if (Model != null && !Model.IsEmpty())
    <img src="@Model.ToString()" alt=""/>
Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

More about EPiServer CMS