Paul Gwamanda
Paul Gwamanda

Reputation: 302

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.

It loops through the articles just fine, however it displays the same image in each

enter image description here

  @{
            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>
            }

Upvotes: 0

Views: 576

Answers (1)

Mario Lopez
Mario Lopez

Reputation: 1465

You are taking the Url from a property of the current node (Model.Content)You should be taking the property from the item in the loop:

@{ string imageUrl = item.GetPropertyValue<IPublishedContent>("articleImage").Url; }

Upvotes: 3

Related Questions