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 5908 posts 22603 karma points MVP 4x 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 3008 posts 13221 karma points MVP 7x 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