Copied to clipboard

Flag this post as spam?

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


  • Keith Roberts 2 posts 72 karma points
    Jun 12, 2017 @ 09:17
    Keith Roberts
    0

    Convert or Return Model.Content.Site() as an "Editable" object such as List and not an IEnumerable

    I need to filter / remove child collections (Sub Pages) that meet a certain criteria. The IEnumerable returned from Model.Content.Site() is uneditable, and i don't want to have to duplicate the entire hierarchy over to an editable list. Is there a way of returning the Content object as a List or an editable object?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jun 13, 2017 @ 13:16
    Alex Skrypnyk
    0

    Hi Keith

    You can use copy of list and make it editable:

    var editableList = Model.Content.Site().Children.ToList();
    

    Alex

  • Keith Roberts 2 posts 72 karma points
    Jun 13, 2017 @ 19:58
    Keith Roberts
    0

    Hi Alex,

    Sorry i should have been clearer with my question.

    I also need the collections within the children to be Lists also.

    When i use ToList() it will just convert the Children i call ToList on and not its child collections also.

    To give some context its for a navigation that will be 3 levels deep, and i will need to remove nodes on any of the levels.

    I was hoping that i wouldn't have to iterate over several levels of IEnumerable Collections converting to Lists and rebuilding the hierarchy in another object.

    Regards,

    Keith

Please Sign in or register to post replies

Write your reply to:

Draft