I have a group of pages on Umbraco which have MediaPickers on them, these pictures will be displayed on the index page as links so that clients can go to a specific page for their product when clicking on them.
I have managed to load the links however, with the below code I can't display the appropriate picture because the following code throws a null reference exception
`var media=Umbraco.TypedMedia(subitem.Properties.Where(x=>x.PropertyTypeAlias=="picture")).SingleOrDefault().Url;`
can anyone help with this? full code is below
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "_SiteMaster.cshtml";
var nodes = umbraco.uQuery.GetNodesByType("productType");
var ProdPage = Umbraco.TypedContent(1087);
}
<header>
<div class = "container-fluid">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">Please Select your Product</h1>
</div>
</div>
<br />
<div class="row">
<div class="col-md-3">
</div>
@*<img src="@Umbraco.Media(item.Id)" class="img-responsive" alt="college">*@
@foreach (var subitem in ProdPage.Children)
{
var media = Umbraco.TypedMedia(subitem.Properties.Where(x=>x.PropertyTypeAlias=="picture")).SingleOrDefault().Url;
<div class="col-md-3">
<a href="@Umbraco.NiceUrl(1087)?PageID=@subitem.Name"><img src=@media alt="Image" /></a>
</div>
}
@*<a href=@SearchURL?PageID=College><img src="/media/1001/college.png" class="img-responsive" alt="college"></a>
</div>
<div class="col-md-3">
<a href=@SearchURL?PageID=Core><img src="/media/1002/Core.png" class="img-responsive" alt="core"> </a>
</div>
<div class="col-md-3">
<a href=@SearchURL?PageID=Salon><img src="/media/1003/Salon.png" class="img-responsive" alt="salon"> </a>*@
</div>
</div>
</div>
</header>