Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
i have 2 doctype articles main and articles item
and i have one partial view listarticlesinhomepage
now foreach loop work good but only display item url and name
when i write item.articlePhotos get errors
please help me :((
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@foreach (var child in Model.Content.AncestorOrSelf().Children.Where(c => c.DocumentTypeAlias.Equals("articlesMain"))) {
<div class="container marketing"> @if(child.Children.Any(x => x.DocumentTypeAlias.Equals("articlesItem"))) { <div class="row"> @foreach(var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("articlesItem"))) { <div class="col-lg-4"> <img src="@item.articlePhotos" /> <!--this line get error please help--> <h2>@page.Name</h2> <p><a class="btn btn-secondary" href="@page.Url" role="button">View details »</a></p> </div> } </div> } </div> }
Hi Demo
Try this code:
@foreach (var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("articlesItem"))) { var mediaItem = item.GetPropertyValue<IPublishedContent>("articlePhotos"); <div class="col-lg-4"> @if (mediaItem != null) { <img src="@mediaItem.Url" /> }<!--this line get error please help--> <h2>@page.Name</h2> <p><a class="btn btn-secondary" href="@page.Url" role="button">View details »</a></p> </div> }
Alex
Thanks Alex. ! Working now...
I'm glad to help, have a nice weekend
Just a quick note that there's a shorter way of doing this:
@foreach (var page in child.Children.Where(p => p.DocumentTypeAlias.Equals("articlesItem")))
which is:
@foreach (var page in child.Children("articlesItem"))
thanks
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Child pages image not display terrible !
i have 2 doctype articles main and articles item
and i have one partial view listarticlesinhomepage
now foreach loop work good but only display item url and name
when i write item.articlePhotos get errors
please help me :((
@foreach (var child in Model.Content.AncestorOrSelf().Children.Where(c => c.DocumentTypeAlias.Equals("articlesMain"))) {
Hi Demo
Try this code:
Alex
Thanks Alex. ! Working now...
I'm glad to help, have a nice weekend
Just a quick note that there's a shorter way of doing this:
which is:
thanks
is working on a reply...