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 6147 posts 24056 karma points MVP 8x 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 13631 karma points MVP 11x 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

Please Sign in or register to post replies

Write your reply to:

Draft