Copied to clipboard

Flag this post as spam?

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


  • Joakim Tveter 2 posts 82 karma points
    Mar 12, 2024 @ 08:36
    Joakim Tveter
    0

    Path is only a negative number (Umbraco helper)

    Hi, I am new to Umbraco and .NET

    I have upgraded a website from Umbraco 7 to Umbraco 13. As a part of my custom search endpoint I need to return a path. The path property only returns a negative number as a string. eg. -1,1440,5787. This is everywhere i use Ubraco Helper. In the Umbraco UI i can see the correct path.

    Please help me.

    my code:

    IEnumerable<IPublishedContent> basicPageContentNodes = _umbracoHelper.ContentAtRoot().SelectMany(root => root.DescendantsOrSelfOfType("BasicPage"));
    
        basicPageNodes = basicPageContentNodes
           .Where(node => node.Name.ToLower().Contains(query.SearchTerm.ToLower()) ||
                                           node.Value<string>("tekst").ToLower().Contains(query.SearchTerm.ToLower()))
                            .Select(node => new SearchResult
                            {
                                Id = node.Id,
                                Name = node.Name,
                                Content = node.Value<string>("tekst"),
                                Path = $"/{node.Path}"
                            })
                            .ToList();
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 12, 2024 @ 10:26
    Nik
    100

    Hi Joakim,

    The Path property is the list of ID's that locate the page, looking at the code I suspect you are after the URL property instead of the Path property.

    Path is a comma separated string of ID's starting with -1 which represents the root level.

    I hope that helps.

    Thanks

    Nik

  • Joakim Tveter 2 posts 82 karma points
    Mar 12, 2024 @ 11:10
    Joakim Tveter
    0

    Thank you. This was a life saver.

Please Sign in or register to post replies

Write your reply to:

Draft