Our monthly Virtual Happy Hour is happening today (Fri Feb 23)!

Try our conversational search powered by Generative AI!

Alloy MVC N00b question 2


In the Alloy MVC project there is a model, partial view and controller for a image file. But it's never used when rendering images on the site? Why not if so?



Mar 25, 2014 10:47

This is being used when dragging images into a content area. It enables you to easily customized the rendering

Mar 25, 2014 12:13

Tank you. So you do not use this when rendering images on a page outside a content area?

Mar 25, 2014 12:58

When rendering an images as a property on a page, a display template is used by default. Check out Image.cshtml under DisplayTemplates in the alloy project

Edited, Mar 25, 2014 13:21

When i look at Index.cshtml for ProductPage i see an image beeing rendered like this:

<div @Html.EditAttributes(x => x.CurrentPage.PageImage)>
        <img src="@Url.ContentUrl(Model.CurrentPage.PageImage)"/>

Why is there an <img> here if you should use image.cshtml? Is not the display template used here? If not, is there an example where it is used?

Mar 25, 2014 14:56

The display template is not used there. It would have been had you typed @Html.PropertyFor(x => x.CurrentPage.PageImage). 

This is done in JumbtronBlockWide.

The way it has been done in ProductPage could be useful if you want to render your image a bit different than normally, but do not want to create a new display template to do that.

Mar 25, 2014 15:05

Thank you for your help!

Mar 25, 2014 15:45

One more question about this:


How do i set the alt text to the Copyright property from the image when the image.cshtml look like this?


@model EPiServer.Core.ContentReference
@if (Model != null)
    <img src="@Url.ContentUrl(Model)" alt="" />

Apr 24, 2014 14:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.