Copied to clipboard

Flag this post as spam?

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


  • bh 291 posts 976 karma points
    Feb 12, 2020 @ 18:04
    bh
    0

    v8 Partial View

    In my partial view I need to traverse the content tree and retrieve a collection of nodes with a specific doct type alias.

    Here's my partial view code...

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = null;
        string filter = ViewData["filter"].ToString();
    
    
        var root = Model.Root().Children().FirstOrDefault(x => x.ContentType.Alias == filter);
        var pages = root.Children()
            .Where(x => x.IsVisible());
    }
    

    Here's where I'm calling the partial view from my view... `@Html.Partial("ItemGrid", new ViewDataDictionary{{ "filter", "itemDetails"}})

    I get this error when it tries to render my partial...

    Value cannot be null. Parameter name: content

    When I step through it, the Model is NULL here...

    var root = Model
    
  • bh 291 posts 976 karma points
    Feb 12, 2020 @ 18:15
    bh
    101

    This worked.

    var currentNode = Umbraco.AssignedContentItem.Root();
    var root = currentNode.Root();
    

    Found the answer on this post: https://our.umbraco.com/forum/templates-partial-views-and-macros/94410-get-current-root-node-from-nested-content-partial-view

  • 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