I am trying to output an image in the following code. But, I am not sure of the syntax in the View. I can type @item.ImageLarge
and some intellisense pops up, but it is not clear how to get the image to display.
View:
@foreach (var item in Model.RotatorContentItems)
{
<h2>@item.SubTitle.Text</h2>
@item.Title.Text
}
Controller:
public ActionResult Index()
{
var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
var dataSource = Sitecore.Context.Database.GetItem(dataSourceId);
var myViewModel = new MyViewModel();
myViewModel.RotatorContentItems = dataSource.Children.Select(c => new RotatorContentItem(c)).ToList();
return View(myViewModel);
}
Model:
public class MyViewModel
{
public List<RotatorContentItem> RotatorContentItems { get; set; }
}
Custom Item:
public partial class RotatorContentItem : CustomItem
{
public static readonly string TemplateId = "{E493DF4A-E97E-49B5-BF9F-F70397EA8D21}";
#region Boilerplate CustomItem Code
public RotatorContentItem(Item innerItem) : base(innerItem)
{
}
public static implicit operator RotatorContentItem(Item innerItem)
{
return innerItem != null ? new RotatorContentItem(innerItem) : null;
}
public static implicit operator Item(RotatorContentItem customItem)
{
return customItem != null ? customItem.InnerItem : null;
}
#endregion //Boilerplate CustomItem Code
#region Field Instance Methods
public CustomTextField Title
{
get
{
return new CustomTextField(InnerItem, InnerItem.Fields["Title"]);
}
}
public CustomTextField SubTitle
{
get
{
return new CustomTextField(InnerItem, InnerItem.Fields["Sub Title"]);
}
}
public CustomImageField ImageLarge
{
get
{
return new CustomImageField(InnerItem, InnerItem.Fields["Image Large"]);
}
}
public CustomImageField ImageSmall
{
get
{
return new CustomImageField(InnerItem, InnerItem.Fields["Image Small"]);
}
}
public CustomGeneralLinkField Link
{
get
{
return new CustomGeneralLinkField(InnerItem, InnerItem.Fields["Link"]);
}
}
public CustomCheckboxField IsOverlayBlack
{
get
{
return new CustomCheckboxField(InnerItem, InnerItem.Fields["Is Overlay Black"]);
}
}
#endregion //Field Instance Methods
}