Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 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 3074 posts 13632 karma points MVP 11x 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

Please Sign in or register to post replies

Write your reply to:

Draft