Copied to clipboard

Flag this post as spam?

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


  • Ken Schnell 35 posts 145 karma points
    Jul 19, 2020 @ 05:59
    Ken Schnell
    0

    Child object of Root gives Null Reference for Object Properties but works fine if not the child object.

    I have a website with different root paths , So for example Home Mechanical

    These are both top level under Content.

    I have a document type with a slider in it and some other properties. My issue is that everything works fine under home, but for what ever reason when on the home page (or others underneath) and browsing to Mechanical the document type that worked fine under root home all of the sudden starts having null reference exceptions on the items with in the Document.

    I am not sure what I am missing - I am thinking something gets messed up with the path to the items.

    Some basic code of the page with issues. Remember it works in the home folder path but when browsing to the Mechanical it does not work - I get the null reference exceptions , the rest of the page objects seem to work fine . Does any one have any idea what I am doing wrong here .Yes I want the structure ..

    @{
        string carouselId = "myCarouselSlide";
        var carousel = Model.Value<IEnumerable<IPublishedElement>>(carouselId);
    }
    
    @if (carousel != null && carousel.Any())
    {
        <div class="carousel slide" style="width:80%;margin: auto;" data-ride="carousel" id="@carouselId">
            <div class="carousel-inner" role="listbox">
                @{
                    int slideCount = 0;
                    foreach (var slide in carousel)
                    {
                        string title = slide.Value<string>("slideTitle");
                        string subtitle = slide.HasValue("slideSubtitle") ? slide.Value<string>("slideSubtitle") : "";
                        string imageUrl = slide.Value<IPublishedContent>("slideImage")?.GetCropUrl(1024,433) ?? Href("~/img/logo.jpg");
                        IEnumerable<Link> links = slide.Value<IEnumerable<Link>>("slideLink");
                        Link link = links != null ? links.FirstOrDefault() : null;
    

    Root Folders

  • 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