Copied to clipboard

Flag this post as spam?

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


  • Alex Skrypnyk 6182 posts 24284 karma points MVP 9x admin c-trib
    Jun 10, 2013 @ 19:22
    Alex Skrypnyk
    0

    Faster foreach

    Please help me to do the for-each via children nodes in the best way ?

    Thanks,

    Alex

  • Jeavon Leopold 3074 posts 13632 karma points MVP 12x admin c-trib
    Jun 10, 2013 @ 19:39
    Jeavon Leopold
    100

    Hi Alex,

    It does depend on if you are using a Razor macro or a Mvc view, for a Razor macro, something like:

    @{
        var root = Model.AncestorOrSelf(1);
    }
    <ul>
        @foreach (var page in root.Children.Where("Visible"))
        { 
            <li><a href="@page.Url">@page.Name</a></li>
        }
    </ul>

    If you are using a Mvc view, something like:

    @{
        var root = Model.Content.AncestorOrSelf(1);
    }
    <ul>
        @foreach (var page in root.Children.Where("Visible"))
        { 
            <li><a href="@page.Url">@page.Name</a></li>
        }
    </ul>

    Is that what you were looking for?

    Thanks,

    Jeavon

  • 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