Copied to clipboard

Flag this post as spam?

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

  • JoskerVemeulen 67 posts 261 karma points
    May 14, 2019 @ 14:33

    limited list - see all link


    I need to show subitems of a node. A simple foreach would do the trick. But i need a limited amount. Max 5 items. If there are more the 5 items it should show a "see all" link.(parent node). If only 3 subitems, the "see all" node should not bu shown ofcourse. Working in v8

    Any help appreciated!

  • Rhys Hamilton 140 posts 941 karma points
    May 14, 2019 @ 14:45
    Rhys Hamilton

    You could use a simple counter variable, like so - and then apply whatever logic you need based on this. For example, if the counter is 5, then show "see more".

        int counter = 1;
        foreach (var i in Model.Children)
            // Apply your own logic based on the counter
            // e.g - if counter == 5, show see all
  • Søren Kottal 611 posts 3896 karma points MVP 4x c-trib
    May 15, 2019 @ 07:56
    Søren Kottal

    Hi Josker

    How about this?

    @foreach (var child in Model.Children.Take(5))
      // show the node
    @if (Model.Children.Count() > 5)
      <a href="/show-all-link">Show all</a>
  • JoskerVemeulen 67 posts 261 karma points
    May 15, 2019 @ 08:05

    Hi Søren,

    Exactly how I did it! I was under the impression that the Take() only works if there are more items. But I was wrong. Thanks!

Please Sign in or register to post replies

Write your reply to: