Copied to clipboard

Flag this post as spam?

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


  • Andrew Smith 3 posts 94 karma points
    Mar 21, 2017 @ 16:35
    Andrew Smith
    0

    Where("Visible") not working in MVC partial view macro

    the following code was taken from the Partial View @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var home = CurrentPage.Site(); }

    @if (home.Children.Where("Visible").Any()) { @* Get the first page in the children *@ var naviLevel = home.Children.First().Level;

    @* Add in level for a CSS hook *@
    <ul class="level-@naviLevel">            
        @* For each child page under the home node *@
        @foreach (var childPage in home.Children.Where("Visible"))
        {   
            if (childPage.Children.Where("Visible").Any())
            {                    
                <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                    @if(childPage.DocumentTypeAlias == "LandingPage") 
                    {
                        <span>@childPage.Name</span>
                        @childPages(childPage.Children)
                    } else {
                        <a href="@childPage.Url">@childPage.Name</a>
                    }
                </li>
            } 
            else
            {
                <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                    <a href="@childPage.Url">@childPage.Name</a>
                </li>
            }            
        }
    </ul>
    

    }

    @helper childPages(dynamic pages) { @* Ensure that we have a collection of pages @ if (pages.Any()) { @ Get the first page in pages and get the level *@ var naviLevel = pages.First().Level;

        @* Add in level for a CSS hook *@
        <ul class="sublevel level-@(naviLevel)">
            @foreach (var page in pages.Where("Visible"))
            {
                <li>
                    <a href="@page.Url">@page.Name</a>
    
                    @* if the current page has any children *@
                    @if (page.Children.Where("Visible").Any())
                    {                        
                        @* Call our helper to display the children *@
                        @childPages(page.Children)
                    }
                </li>
            }
        </ul>
    }
    

    } This was used to create a Partial View Macro and the associated macro. It returned the navigation but the Where("Visible") was not working. It showed all items in the nav. The navigation script was working with this parameter. The macro was tested by including it in a webforms template. What am not doing correctly?

  • Andrew Smith 3 posts 94 karma points
    Mar 21, 2017 @ 20:53
    Andrew Smith
    100

    Problem resolved - the content with umbracoNaviHide had not been published correctly. Please ignore the Macro based on a Macro Partial View works on both a Webforms template and Razor view template

Please Sign in or register to post replies

Write your reply to:

Draft