AI OnAI Off
You could do something like this:
@Html.PropertyFor(x => x.Image, new { AltText = "something" })
and then in your image display template (typically image.cshtml):
<img src="@Url.ContentUrl(Model)" alt="@ViewBag.AltText" />
Do you have any DisplayTemplate for `Url` model?
One of the possibility to implement this is to have a specific display template for `EPiServer.Url` property.
Page type definition:
[UIHint(UIHint.Image)]
[Display(Name = "Image url", Order = 10)]
public virtual Url ImageUrl { get; set; }
Display template (usually located at /Views/Shared/DisplayTemplates/Image.cshtml):
@model EPiServer.Url
@if (Model != null && !Model.IsEmpty())
{
<img src="@Model" alt="@(ViewData.ContainsKey("alt") ? ViewData["alt"] : string.Empty)"/>
}
Usage in view:
@Html.PropertyFor(x => Model.CurrentBlock.MainImage, new { alt = "jellycat" })
Thanks everyone for your responses. I've implements Per's solution which is working nicely.
Thanks for all the help - much appreciated
Hi all
I'm trying to do something that I thought would be sinmple bu tisn't. I have a contentreference property with an image ui hint. I want to display this in a view with another page property that represents its alt text. I have
The image comes out bu the alt text doesn't. I undetsand why - the second param is for specific functionality - custom tags.
So hiow to do it. I could write it out manually then pwerhaps put into a display template with a suitable model but then what is the best way to get the contentreference to the image url. Is there a helper availabel in the View to do this?
Please help - i'm being frustrated by a simple task
Thanks