Copied to clipboard

Flag this post as spam?

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


  • Johan 188 posts 380 karma points
    Oct 10, 2014 @ 10:58
    Johan
    0

    Order nodes

    I want to list all my featured news at the top but i can't get them in the right order. This is what i got:

    var featuredNewsCollection = allNewsCollection.Where(x => featuredNewsIds.Contains(x.Id));
    

    This lists the featured news in the order they appear in allNewsCollection. I want them in the order from my featuredNewsIds int list. Is there a smart way to rearrange this?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 10, 2014 @ 11:19
    Dennis Aaen
    0

    Hi Johan,

    Maybe you could do something like this:

    var featuredNewsCollection = allNewsCollection.Where(x => featuredNewsIds.Contains(x.Id)).OrderBy(featuredNewsIds);

    Hope this helps,

    /Dennis

  • Johan 188 posts 380 karma points
    Oct 13, 2014 @ 10:20
    Johan
    0

    @Dennis That generates this error message:

    Compiler Error Message: CS1928: 'System.Linq.IQueryable<Umbraco.Core.Models.IPublishedContent>' does not contain a definition for 'OrderBy' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.OrderBy(System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>, string)' has some invalid arguments
    

    Edit: featuredNewsIds is a list of IDs. I asked the question at Stackoverflow too. http://stackoverflow.com/questions/26339794/reorder-umbraco-razor-nodes

  • Johan 188 posts 380 karma points
    Oct 15, 2014 @ 17:14
    Johan
    100

    Got this answer on Stack Overflow

    var featuredNewsCollection = allNewsCollection.Where(x => featuredNewsIds.Contains(x.Id)).OrderBy(x => featuredNewsIds.IndexOf(x.Id));
    

    Worked!

Please Sign in or register to post replies

Write your reply to:

Draft