Copied to clipboard

Flag this post as spam?

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


  • Matt 358 posts 840 karma points
    Jan 25, 2022 @ 11:20
    Matt
    0

    Code not working on Umbraco 9

    Hi all,

    I had this navigation partial view working in Umbraco8, but doesnt seem to work on Umbraco 9

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using Umbraco.Cms.Core
    @using Umbraco.Cms.Core.Models.PublishedContent
    @using Umbraco.Cms.Core.Routing
    @using Umbraco.Extensions
    
    @inject IPublishedValueFallback PublishedValueFallback
    @inject IPublishedUrlProvider PublishedUrlProvider
    
    
    @{
        var selection = Umbraco.ContentAtRoot().FirstOrDefault()
        .Children()
        .Where(x => x.IsVisible());
    }
    
    <div data-collapse="medium" data-animation="default" data-duration="400" class="navbar w-nav">
        <nav role="navigation" class="nav-menu w-nav-menu">
            <a href="/" class="link-block w-inline-block w--current"><img src="~/images/home_1home.png" alt="Home"></a>
            @foreach (var item in selection)
            {
                var children = item.Children(c => c.IsVisible()).ToArray();
                if (!item.Value<bool>("disableDropdown") && (children.Any()))
                {
                    <div data-hover="1" data-delay="0" class="dropdown-link w-dropdown">
                        <div class="dropdown-toggle w-dropdown-toggle">
                            <div class="testt">@item.Name</div>
                        </div>
                        <nav class="w-dropdown-list">
                            @foreach (var child in children)
                            {
                                <a href="@child.Url" class="nav-link w-dropdown-link">@child.Name</a>
    
                            }
                        </nav>
                    </div>
                }
                else
                {
                    <a href="@item.Url" class="nav-link w-nav-link">@item.Name</a>
                }
            }
        </nav>
        <div data-ix="triangle-nav" class="triangle-nav-button w-nav-button">
            <div class="triangle"></div>
        </div>
    </div>
    

    But Im getting the following error when trying to use it in umbraco 9?

    enter image description here

  • Patrick de Mooij 72 posts 622 karma points MVP 3x c-trib
    Jan 25, 2022 @ 12:16
    Patrick de Mooij
    101

    Hi Matt,

    De .Url variable doesn't exists anymore in v9. You now have to use the method .Url()

Please Sign in or register to post replies

Write your reply to:

Draft