Copied to clipboard

Flag this post as spam?

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


  • Craig100 1078 posts 2366 karma points c-trib
    Mar 06, 2015 @ 22:03
    Craig100
    0

    Iterating through an IPublishedContent collection

    Converting a previously working menu to strongly typed in V7.2.2

    var home = Model.Content.AncestorOrSelf();
    var pageCollection = home.Children;

    var topPages = pageCollection.Where(x => x.IsVisible() && x.GetPropertyValue<bool>("showInTopMenu"));

    @foreach (var page in topPages) { <------Fails, says previous line is NullReferenceException

    I suspect I can't just "foreach" through it, but can't find reliable info :(

    If I put topPages out to the page I get 

    System.Linq.Enumerable+WhereEnumerableIterator`1[Umbraco.Core.Models.IPublishedContent]

    Any clues or links appreciated.

    Craig

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Mar 06, 2015 @ 22:13
    Jeavon Leopold
    0

    Yes, you can as its a enumerable. I'm assuming you expect topPages to not be empty?

    Could post the whole code and the whole error?

    Jeavon

  • 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