Copied to clipboard

Flag this post as spam?

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

  • bh 266 posts 926 karma points
    Feb 12, 2020 @ 18:04

    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 266 posts 926 karma points
    Feb 12, 2020 @ 18:15

    This worked.

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

    Found the answer on this post:

Please Sign in or register to post replies

Write your reply to: