I have this bit of razor in a partial view that is going through and making a list of nodes. For some reason, if I add "Take(3)" or any other number, it returns no results...Without the take stament it returns 6 items.
Any idea why this would be?
-Amir
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var root = CurrentPage.AncestorOrSelf(); var nodes = root.Descendants("Event"); string switchStatus = @CurrentPage.calendarFeed.ToString(); }
@{
<section class="feed calendar"> <nav> <ul>
@foreach(var page in nodes.OrderBy("eventStartDateTime").Take(3)){ var eventDate = @page.EventStartDateTime; var today = DateTime.Now; <span></span> if(eventDate > today) { <li> <time><h2>@page.eventStartDateTime.ToString("MMMM-dd-yyy hh:mm tt")</h2></time> <a href="@page.Url">@page.EventTitle</a> </li>
Yep OrderBy des and then Skip(3) should do it, How are you asserting that the first 3 in that collection are the ones you want to skip? seems a bit risky :/. Charlie
Odd results with OrderBy and Take
Hi,
I have this bit of razor in a partial view that is going through and making a list of nodes. For some reason, if I add "Take(3)" or any other number, it returns no results...Without the take stament it returns 6 items.
Any idea why this would be?
-Amir
Well, apparently I was just approaching this a bit backward. OrderBy desc and Skip(3) gave me the desired results.
-Amir
Yep OrderBy des and then Skip(3) should do it, How are you asserting that the first 3 in that collection are the ones you want to skip? seems a bit risky :/. Charlie
I wasn't, I'm actually still not sure what the best way to approach this is. Any suggestions?
-Amir
Hi Amir Just reading this again. Sorry for the late reply. I am not getting notifications an been busy
Have you debugged this?
The IEnumerable
so nodes.Count() should be > 0
if we do nodes.Take(3) should give you the first three items in the collection.
The reason i think you are having problems is because of:
eventStartDateTime
What you are trying to do i orderBy eventStartDateTime on an object not a property of an object if that makes sense.
You will need something like OrderBy(x=>x.properties).Where(x=>x.Alias == eventStartDateTime)
Something like that. I will try an give you a working example tomorrow morning.
Hope this helps.
Thanks,
Charlie :)
is working on a reply...