Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Nov 09, 2017 @ 10:33
    Paul Griffiths
    0

    Related Links data type | Null reference when selecting internal umbraco page

    Hi All,

    I have used the related link data type on multiple projects and have had never had any issues until now. I have recently installed Umbraco version 7.7.2 assembly: 1.0.6484.21641 and use the following (cut down version) code to display a link specified in the back office

    @{
        var siteRoot = Model.Content.AncestorOrSelf("homePage");
        var carouselLandingPage = siteRoot.Descendant("carouselLandingPage");
    }
    
     <div class="carousel-inner text-center">
            @foreach (var carouselSlide in carouselLandingPage.Children)
            {
                                    foreach (var link in carouselSlide.GetPropertyValue<JArray>("buttonLink"))
                                    {
                                        var linkUrl = (link.Value<bool>("isInternal")) ? Umbraco.NiceUrl(link.Value<int>("internal")) : link.Value<string>("link");
                                        var linkTarget = link.Value<bool>("newWindow") ? "_blank" : null;
    
                                        <p class="slide-btn">
                                            <a title="@(link.Value<string>("caption"))" href="@linkUrl" target="@linkTarget" class="btn btn-white btn-lg">@(link.Value<string>("caption"))</a>
                                        </p>
                                    }
                                }
                            </ul>
                        </div>
                    </div>
                </div>
            }
    
        </div>
    

    Whenever i specifiy an internal umbraco page i get the following

    enter image description here

    However, when i specify an external link (see below) there is no problems and everything works perfectly

    enter image description here

    Is this a bug or is there an issue with something im doing? I have used this code (taken from https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/related-links) on multiple projects and never had an issue before?

    Thanks Paul

  • Barry Fogarty 493 posts 1129 karma points
    Nov 09, 2017 @ 11:15
    Barry Fogarty
    100

    Hi Paul,

    As the link to that property editor says, that type is now obsolete. Refactor your code to the updated Related Link type as found here:

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Related-Links2

  • Paul Griffiths 370 posts 1021 karma points
    Nov 09, 2017 @ 11:35
    Paul Griffiths
    0

    HI Barry,

    Thanks for responding!

    Thanks a very good point, totally missed the 'H1' obselete info :)!

    Ill refactor my code using the link you provided.

    Thanks Paul

  • Paul Griffiths 370 posts 1021 karma points
    Nov 12, 2017 @ 20:43
    Paul Griffiths
    0

    Hi guys,

    Just to follow up i implemented the code from the link Barry provided (https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Related-Links2) and this now works as expected.

    Couple of points

    1. Ensure the following is true EnablePropertyValueConverters (found in umbracoSettings.config)
    2. add the following using statement @using Umbraco.Web.Models

    Final Code enter image description here

    Thanks Paul

Please Sign in or register to post replies

Write your reply to:

Draft