Copied to clipboard

Flag this post as spam?

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


  • Wayne 19 posts 59 karma points
    Sep 11, 2013 @ 14:20
    Wayne
    0

    Why is AncestorsOrSelf returning null reference exception?

    in an umberco template i have the following code

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
    Layout = null;
    var homepageNode = CurrentPage.AncestorsOrSelf(1);
    }

    It keeps returning "Object reference not set to an instance of an object."

    I have also tried
    CurrentPage.AncestorsOrSelf(1).FirstOrDefault()

    I've looked at lots of blog posts and cant seem to see the problem.

    Can anyone point me in the right direction?

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 11, 2013 @ 18:30
    Ali Sheikh Taheri
    0

    Try this:

    Umbraco.TypedContentAtRoot().SingleOrDefault()
    
  • Charles Afford 1163 posts 1709 karma points
    Sep 14, 2013 @ 12:08
    Charles Afford
    0

    What is you currentPage.  Have you checked that object to see what children and what ancestors it has?  Charlie?

Please Sign in or register to post replies

Write your reply to:

Draft