Copied to clipboard

Flag this post as spam?

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


  • Danny 9 posts 28 karma points
    Jul 16, 2014 @ 10:35
    Danny
    0

    multiple orderby in cshtml

    I try to do a multiple orderby for sorting pages that can be used as newsitems.

    allPages = Model.AncestorOrSelf(1).Descendants().Where("showAsNews").OrderBy("newsdate desc")

    This works fine, but it goes wrong if multiple pages are made on a single date I want to add a second field to order on.

    but things like .OrderBy("newsdate desc").OrderBy("id desc") .OrderBy("newsdate, id desc") .OrderBy("newsdate ").ThenByDescending("id") all don't work. Or the sorting on ID is ignored, or errors like

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'ThenBy' at CallSite.Target(Closure , CallSite , Object , String )

    are returned.

    Also something like Listpages = new DynamicNode(1962).DescendantsOrSelf("Aantekening").Items.OrderByDescending(a => a.CreateDate).ToList().Take(5).ToList(); which I found isn't working, using => in here returns an error I cannot use a lambda expression.

    So is there a way to just simply chain 2 orderBy's so the items can be sorted correctly?

    running on Umbraco 6.1.6

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jul 19, 2014 @ 22:27
    Andy Butland
    0

    Does this help?

    Andy

Please Sign in or register to post replies

Write your reply to:

Draft