Copied to clipboard

Flag this post as spam?

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


  • Blake Watt (Clerke) 106 posts 351 karma points MVP
    Aug 04, 2012 @ 05:00
    Blake Watt (Clerke)
    0

    foreach 3rd item in dynamic list create new ul

    I apologize if something like this has been answered before, I am fairly new to razor so I'm sure I am probably doing this completely wrong but I gave it my best shot and now I need help.

    @{
      
      var skills Model.Children;
      
      foreach (var list in skills.Count(<= 3){
        <ul class="skills">
          @foreach(var item in list){
            <li><span style="width:@{@item.percentage};">@item.Name</span></li>
          }
        </ul>
      }
      
    }

     

    My Goal is for every 3rd child I want to create a new ul. Each ul will then have 3 li items underneath it. I've attempted .Count() and .Take(3) but I know I wasn't doing it correctly because I keep getting error loading macro engine script. I'm not sure if that was would even be the correct way to go about it.

     

    Thanks for any help in advance. I appreciate it.

    -Blake

  • Richard Brookes 34 posts 57 karma points
    Aug 05, 2012 @ 10:42
    Richard Brookes
    0

    Hi Blake,

    I think what you may be looking for is something like this

    @foreach(var group in Model.Children.InGroupsOf(3))
    {
       <ul class="skills">
          @foreach(var item in group)
          {
             <li>@item.Name</li>
          }
       </ul>
    }

    This is just from memory so you might need to check it

    Thanks

     

     

     

  • Blake Watt (Clerke) 106 posts 351 karma points MVP
    Aug 05, 2012 @ 23:24
    Blake Watt (Clerke)
    0

    Thank you so much!! that worked :)

  • Richard Brookes 34 posts 57 karma points
    Aug 06, 2012 @ 02:00
    Richard Brookes
    0

    No problem, glad I could help.

Please Sign in or register to post replies

Write your reply to:

Draft