Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello,
I am trying to order my news items inside a foreach loop by CreateDate but I cant get it working
foreach (dynamic newsItem in item.NewsItem.OrderBy("CreateDate desc"))
Hi Dominik
Try something like
var sortedItems = newsItems.Children.Where("Visible").OrderBy("createDate descending");@foreach (dynamic page in sortedItems){//}
HI Fuj,
Instead of my foreach loop? Can you also please explain why my statement does not work?
Thanks
Hi Dominik,
Not sure why your foreach loop is not working, could you post your whole code?
//fuji
Try this instead of your foreach loop
@foreach (dynamic newsItem in item.NewsItems.Where("Visible").OrderBy("CreateDate desc")) {//}
or this
@foreach (dynamic newsItem in item.Children.Where("Visible").OrderBy("CreateDate desc")) {//}
Perhaps you have forgot the 's' of the end of 'NewsItem' in your foreach loop.
Sören
They are document types with alias "NewsItem" under your current node? If yes, you must use Model instead of item in your foreach loop.
I have created a document type "News" with child items "News Items". Now i want to show the latest created news.
Here is the complete code
foreach (dynamic item in Model.AncestorOrSelf().News) { foreach (dynamic newsItem in item.NewsItems.Where("Visible").OrderBy("CreateDate desc")) {
}
Sorting still does not work
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Order by in foreach
Hello,
I am trying to order my news items inside a foreach loop by CreateDate but I cant get it working
foreach (dynamic newsItem in item.NewsItem.OrderBy("CreateDate desc"))
Hi Dominik
Try something like
HI Fuj,
Instead of my foreach loop? Can you also please explain why my statement does not work?
Thanks
Hi Dominik,
Not sure why your foreach loop is not working, could you post your whole code?
//fuji
Hi Dominik,
Try this instead of your foreach loop
or this
Perhaps you have forgot the 's' of the end of 'NewsItem' in your foreach loop.
Sören
They are document types with alias "NewsItem" under your current node? If yes, you must use Model instead of item in your foreach loop.
I have created a document type "News" with child items "News Items". Now i want to show the latest created news.
Here is the complete code
foreach (dynamic item in Model.AncestorOrSelf().News)
{
foreach (dynamic newsItem in item.NewsItems.Where("Visible").OrderBy("CreateDate desc")) {
}
}
Sorting still does not work
is working on a reply...