Copied to clipboard

Flag this post as spam?

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

  • Craig 34 posts 270 karma points
    Sep 19, 2016 @ 17:44

    List of IPublishedContent to ContentModel


    I'm looking to find a nice way to convert a list of IPublishedContent objects to their strongly typed ContentModel equivalent but I can't figure it out.

    The code I would usually use would be something like:

    IList<IPublishedContent> courses = Model.Content.Descendents().Where(x => x.DocumentTypeAlias == "course");

    What I'd like to do is end up with the left hand side looking something like:

    IList<ContentModels.Course> courses = Model.Content etc etc

    Is this possible to do without putting using a mapper?

  • Craig 34 posts 270 karma points
    Sep 19, 2016 @ 18:14

    Ahem. Never mind I was just being a little thick as I've done this a million times in a non Umbraco environment. Here's my solution:

    IList<ContentModels.Course> courses = Model.Content.Descendants().Where(x => x.DocumentTypeAlias == "course").Select(x => (ContentModels.Course)x).ToList();
Please Sign in or register to post replies

Write your reply to: