Copied to clipboard

Flag this post as spam?

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


  • Darren Wilson 238 posts 646 karma points
    Jun 07, 2016 @ 10:44
    Darren Wilson
    0

    .Take(1).OrderBy("date") displays SortOrder

    Hi Folks,

    Is there a minimum quantity allowed for .Take(X)? I'm looking to display just one node which has the most recent 'date' field - it works with .Take(8) and above, but below it displays the SortOrder - here's my partial:

    @{
    var selection = CurrentPage.Site().FirstChild("NewsRepository").Children("NewsItem").Where("Visible").Take(1).OrderBy("date desc");}<ul class="news-feed">
    @foreach(var item in selection){
        <li>
            <h4><a href="@item.Url">@item.Name</a></h4>
            <span style="color:#888; font-size:14px">
            @item.Date.ToLongDateString()
            </span>
        </li>
    }</ul>@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    Thanks Darren

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jun 07, 2016 @ 10:49
    Dirk De Grave
    100

    Darren,

    you'd need to .OrderBy() first before performing a .Take()

    --Dirk

  • Darren Wilson 238 posts 646 karma points
    Jun 07, 2016 @ 10:54
    Darren Wilson
    0

    Hi Dirk,

    This solved it! I would have never guessed that!

    Darren

  • 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