Copied to clipboard

Flag this post as spam?

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


  • ibrahim TUNC 54 posts 132 karma points
    Feb 22, 2018 @ 13:01
    ibrahim TUNC
    0

    Cogworks Meganav v1.1.1 Help

    Hello, when I wrote for in the children items .Where(x => x.Content.IsVisible()) I get an error message.

    Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 23: { Line 24:

    Line 25: @foreach (var subMenu in item.Children.Where(x => x.Content.IsVisible())) Line 26: { Line 27: Source File: e:\Projects\Microsoft\devISKUR v7.8.1\umbISKUR-dev(v7.8.1)\Views\Partials\USNNavigation\USNMainNavigation.cshtml Line: 25

    Where am I doing wrong? Can you help me? please.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Umbraco.Web; @using Umbraco.Web.Models; @using Cogworks.Meganav.Models; @{ var navigationNodeID = Umbraco.TypedContent(1075); var test = navigationNodeID.GetPropertyValue("USNMainNavigation");

    <ul class="nav navbar-nav pull-right">
        @foreach (var item in navigationNodeID.GetPropertyValue<IEnumerable<MeganavItem>>("USNMainNavigation"))
        {
            <li class="dropdown">
                <a href="@item.Url" target="@item.Target" id="@item.Id" class="nav-link"  data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">@item.Title <span class="caret"></span></a>
    
                @*@if (item.Children.Where(x => x.Content.GetProperty("isVisible")).Any())*@
    
                @if (item.Children.Any())
                {
                    <ul class="dropdown-menu">
                        @foreach (var subMenu in item.Children.Where(x => x.Content.IsVisible()))
                        {                                
                            <li>
                                <a href="@subMenu.Url" class="nav-link">@subMenu.Title</a>
                            </li>
                        }
                    </ul>
                }
    
            </li>
    
        }
    </ul>
    

    }

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Feb 22, 2018 @ 13:38
    Nik
    100

    Hi Ibrahim,

    I think you need to check that Content is set, you might find that it doesn't always have a content node behind it.

    So, change your foreach declaration to this:

    @foreach (var subMenu in item.Children.Where(x => x.Content != null && x.Content.IsVisible()))
    

    Thanks,

    Nik

  • ibrahim TUNC 54 posts 132 karma points
    Feb 22, 2018 @ 14:04
    ibrahim TUNC
    1

    Thanks Nik. It's Works.

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Feb 22, 2018 @ 14:24
    Nik
    0

    No problem, pleased it's all sorted for you :-)

  • ibrahim TUNC 54 posts 132 karma points
    Feb 22, 2018 @ 17:07
    ibrahim TUNC
    0

    Hi! Nik

    Can I ask you one more question in this code? If I want to make a 4 Levels navigation, how should I follow a road?

Please Sign in or register to post replies

Write your reply to:

Draft