locked
for each loop RRS feed

  • Question

  • User1519602350 posted

    Below code generates thumbnail box for my portfolio. Totally I have 8 portfolio images i.,e portfolio1.png portfolio2.png.. My requirement is for each loop it needs to be inserted each portfolio image(below underlined where i need). kindly advise me.

                                @foreach(var subMenuCategories in subcategory)
                                {
     
        <!-- START PORTFOLIO ITEM -->                   
        <div class="portfolio-item one-third column design videography photography web branding" style="border: 0px solid red;">
               <div class="portfolio">
                    
                    <div style=" height: 200px; ">
                      <img src="portfolio1.png"/><!-- END PORTFOLIO IMAGE -->   
                    </div>
     </div>
    Tuesday, September 23, 2014 2:12 PM

Answers

  • User281315223 posted

    So you want to just insert the appropriate number from the loop within your markup? If so, you should be able to use something like the following with a for-loop instead :

    @for(int i = 1; i <= subcategory.Count(); i++)
    {
        <!-- START PORTFOLIO ITEM -->                   
        <div class="portfolio-item one-third column design videography photography web branding" style="border: 0px solid red;">
            <div class="portfolio">
                <div style=" height: 200px; ">
                    <img src="portfolio@i.png"/>  
                </div>
            </div>
        </div>
    }

    Although it's possible this could cause an issue due to the '.' character, so you might need to wrap your property name within parentheses as seen below:

    @for(int i = 1; i <= subcategory.Count(); i++)
    {
        <!-- START PORTFOLIO ITEM -->                   
        <div class="portfolio-item one-third column design videography photography web branding" style="border: 0px solid red;">
            <div class="portfolio">
                <div style=" height: 200px; ">
                    <img src="portfolio@(i).png"/>  
                </div>
            </div>
        </div>
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 23, 2014 2:24 PM