Copied to clipboard

Flag this post as spam?

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


  • Michael Brydebøl 12 posts 32 karma points
    Mar 19, 2013 @ 12:54
    Michael Brydebøl
    0

    Sort with two different dates

    Hi

    I have some news items that are sorted by the "Create date" value.

    Now that the client are moving all the old news from their old site to this new site I have made a date picker so it's possible for the client to set the old date of the news.

    How can I with razor first sort after the date picker I have made and if the client haven't specified a date then sort after the normal "Create date"?

    Thanks in advance.

  • Andreas Iseli 150 posts 427 karma points
    Mar 19, 2013 @ 17:55
    Andreas Iseli
    0

    If you have a list that inherits from IQueryable then just use Linq like this:

    IEnumerable<YourItem> sortedItems = items.OrderBy(i => i.FirstDate).ThenBy(i => i.SecondDate);

    If you require descendend sorting, the use OrderByDescending and ThenByDescending.

    Regards

  • Michael Brydebøl 12 posts 32 karma points
    Mar 20, 2013 @ 10:35
    Michael Brydebøl
    0

    I'm not using Linq but just normal Razor.

    Is it possible when I just have some nodes with my own "Publishdate" value and the "Create date" value and then sort the nodes with Razor?

  • Andreas Iseli 150 posts 427 karma points
    Mar 20, 2013 @ 11:01
    Andreas Iseli
    0

    Just import Linq in your view using

    @using System.Linq;
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies