Copied to clipboard

Flag this post as spam?

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


  • tofu 9 posts 89 karma points
    Sep 20, 2018 @ 13:55
    tofu
    0

    AssignedContentItem.AncestorOrSelf("alias") returns null

    IPublishedContent news = Umbraco.AssignedContentItem.AncestorOrSelf("news");
    IEnumerable<IPublishedContent> newsPosts = news.Children.Where(x => x.IsVisible() && x.DocumentTypeAlias == "newsPost").OrderByDescending(x => x.UpdateDate).Take(numberOfItemsToDisplay);
    

    Hi, as the title goes. I'm trying to get an IEnumerable of

    In the first line, I assign the news page to the a variable "news", of IPublishContent. In the second line, I'm getting the list of posts dangling below that page. (I'm only only a limited number of them, which I specified with "Take(numberOfItemsToDisplay)"

    Here I'm getting an error on the second line, saying "news" was null.

    Since I clearly specified the alias when instantiating it, I have no idea why it went wrong.

    Could you tell us possible reasons if you have any clue...?

    Waiting for your comments!

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Sep 23, 2018 @ 22:20
    Paul Seal
    0

    Hi Tofu This error suggests to me that the page you are loading this on, does not have the document type alias of "news" and neither do any of it's ancestors. Ancestors goes back up the tree towards the top node.

    Check the alias is correct.

    Make sure you are not trying to call this from a page which is nothing to do with the news doc type.

    Kind regards

    Paul

  • tofu 9 posts 89 karma points
    Oct 11, 2018 @ 02:00
    tofu
    0

    Make sure you are not trying to call this from a page which is nothing to do with the news doc type.

    Excuse me for my delayed response. Thank you for your suggestion. I was calling the page from an irrelevant page as you expected. I changed the master template, and I was able to display the page as intended!

    Kind Regards, tofu

Please Sign in or register to post replies

Write your reply to:

Draft