Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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!
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
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>
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!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted