[英]Umbraco 7 foreach loops through same image
Having a bit of difficulty displaying images correctly in a foreach loop in Umbraco, am noob in C# and Umbraco. 在Umbraco的foreach循环中正确显示图像有些困难,在C#和Umbraco中是菜鸟。
It loops through the articles just fine, however it displays the same image in each 它可以很好地遍历文章,但是每篇文章都显示相同的图像
@{
var articles = Model.Content.Site().FirstChild("perspectives").Children()
.Where(x => x.IsVisible());
}
@foreach (var item in articles.Take(5))
{
<div class="related-article">
<a href="@item.Url">
<div class="gray-block-article-block">
@{ string imageUrl = Model.Content.GetPropertyValue<IPublishedContent>("articleImage").Url; }
<img src="@imageUrl" alt="@item.Name">
<div>@Umbraco.Truncate(library.StripHtml(item.Name), 20)</div>
</div>
</a>
</div>
}
您将从当前节点(Model.Content)的属性获取Url您应从循环中的项目获取属性:
@{ string imageUrl = item.GetPropertyValue<IPublishedContent>("articleImage").Url; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.