Displaying images from multiple media picker in partial view
I am currently creating a partial view that will display a specific image from a multiple media picker property. The code i have for my partial view right now is this:
@{
var selection = Umbraco.TypedContent(1090).Children()
.Where(x => x.IsVisible())
.OrderBy("CreateDate");
}
@foreach(var item in selection){
<div class="col-sm-12 col-md-6">
<a class="thumbnail fancybox" rel="" href="images/sommerhuse/3.jpg">
<img class="img_wr" alt="" src="images/sommerhuse/3.jpg" />
</a>
</div>
<div class="col-sm-12 col-md-6">
<h5><strong>@item.GetPropertyValue("sommerhusOverskrift")</strong></h5>
<p class="static-height">@item.GetPropertyValue("sommerhusKortBeskrivelse")</p>
<a class="subpage_btn btn_top_offset" href="@item.Url">Tryk for at se Mere</a>
</div>
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
For the image source i want the first image in my multiple media picker.
I am unsure how to accomplish this. Before i have used code like this to display an image from the media archive:
Displaying images from multiple media picker in partial view
I am currently creating a partial view that will display a specific image from a multiple media picker property. The code i have for my partial view right now is this:
For the image source i want the first image in my multiple media picker.
I am unsure how to accomplish this. Before i have used code like this to display an image from the media archive:
You can get the first image in a multimedia picker like this:
But I'd be very wary of doing this as you'll get an exception if there are no images selected. You might want to break code down:
Then use
backgroundUrl
as the value for your background image URL.is working on a reply...