Copied to clipboard

Flag this post as spam?

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


  • Josh Bula 13 posts 75 karma points
    Apr 18, 2017 @ 18:12
    Josh Bula
    0

    Related Links in 7.6 RC - List of links is always NULL when an internal link is included

    I'm getting an 'object reference not set to an instance of an object' error on the JArray of relatedLinks for a page whenever there is an internal link.

    Lists of links that are only external work fine, but if there is just one internal link, the whole array is null.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @using Newtonsoft.Json.Linq
    
    @{
        var query = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where("Visible && DocumentTypeAlias == @0", "newsItem").OrderBy("sortOrder desc");
    }
    
    @foreach (var page in query)
    {
        <h1>@page.Headline</h1>
        <p>@page.body</p>
    
        if (page.HasValue("relatedLinks") && page.GetPropertyValue<string>("relatedLinks").Length > 2)
        {
            var links = page.GetPropertyValue<JArray>("relatedLinks"); // <--- Always null if an internal link is included in the collection of links
    
            foreach (var item in links)
            {
                var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.Value<string>("link");
                var linkTarget = item.Value<bool>("newWindow") ? "_blank" : null;
                <p><a href="@linkUrl" target="@linkTarget">@(item.Value<string>("caption"))</a></p>
            }
    
        }
    }
    

    Is this a bug in 7.6 or am I doing something wrong?

    If I switch from Typed to Dynamic, I get a completely different problem that I posted about here

    Thanks!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 19, 2017 @ 06:31
    Dave Woestenborghs
    100

    Hi Josh,

    I replied to this in the other thread

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft