Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Churchley 272 posts 1258 karma points c-trib
    May 31, 2014 @ 22:19
    John Churchley
    0

    foreach in razor with counter

    I'm trying to use a foreach loop for a slider but having issues with adding 1 to the counter on each pass.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

    var promoItems = CurrentPage.HeroRepositories.First().HeroItems.Where("Visible");

    int bannerCount=1;

    }

     

    <div class="visible-lg">

        <ul class='kwicks kwicks-horizontal'>

    @foreach (var item in promoItems){

            <li id="panel-@bannerCount"><img style="max-width:inherit;" src="@item.GetCropUrl("bannerImage", "heroimage-w800-h400")" alt=""><div class="slide-description"><h1>@item.Title</h1><h4>@item.subheading</h4></div></li>

    @bannerCount++

    }

        </ul>

    </div>

  • Dan 1288 posts 3942 karma points c-trib
    May 31, 2014 @ 22:36
    Dan
    1

    Hi John,

    Try changing @bannerCount++ to just bannerCount++. Does that work?

  • John Churchley 272 posts 1258 karma points c-trib
    Jun 01, 2014 @ 00:07
    John Churchley
    100

    Thanks for the suggestion but realised just after I posted the question the answer was @@bannerCount++ as I needed to explicitly escape out

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies