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
Hi all
I am trying to order my list of nodes by createdate in decsending order. Here is my code that is failing:
IEnumerable<IPublishedContent> articles;
if (string.IsNullOrEmpty(suburb))
{
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderBy("createDate desc");
}
.OrderByDescending("createDate") ??
Nope, tried that too.
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending("createDate desc");
Fails.............
http://our.umbraco.org/forum/developers/razor/42030-Sort-by-price-razor
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending(x
=> x.createDate);
??
Hi hugh,
You should be able to apply the LINQ OrderByDescending() syntax for this query.
OrderByDescending(x=>x.CreateDate)
Hi Fuji
No, that still does not work. Causes a macro error.
Here is the code (inlcuding your orderby)
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Linq;
@{
var articleContainerId = 1067;
var topCat = Request.QueryString["topCat"];
var subCat = Request.QueryString["subCat"];
var suburb = Request.QueryString["sub"];
var categoryId = CurrentPage.Id.ToString();
var idToUse = string.Empty;
int pageSize = 25;
int page = 1; // The page we are viewing
if (!int.TryParse(Request.QueryString["page"], out page))
page = 1;
if (!string.IsNullOrEmpty(topCat))
idToUse = topCat;
if (!string.IsNullOrEmpty(subCat))
idToUse = subCat;
if (string.IsNullOrEmpty(idToUse))
idToUse = categoryId;
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending(x=>x.CreateDate);
else
if (topCat == "1")
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue("suburb".ToUpper()).Equals(suburb.ToUpper()));
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).Where(x => x.GetPropertyValue("suburb".ToUpper()).Equals(suburb.ToUpper()));
int totalNodes = articles.Count();
int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
if (page > totalPages)
page = totalPages;
else if (page < 1)
foreach (var p in articles.Skip((page - 1) * pageSize).Take(pageSize))
var advImgStr = p.GetPropertyValue<string>("photos").Split(',');
var selectedMedia = Umbraco.Media(advImgStr[0]);
var bId = p.GetPropertyValue("broker");
var strPrice = p.GetPropertyValue("salePrice");
var featureClass = "";
if (p.GetPropertyValue<bool>("isFeatured"))
featureClass = "background-color:#b7b8b8; padding:5px;";
<article style="@featureClass">
@if (p.GetPropertyValue<bool>("isFeatured"))
<p><strong>FEATURED AD</strong></p>
<a href="@p.Url" class="single-image picture">
<img src="/imageGen.ashx?image=@selectedMedia.umbracoFile&width=190&height=115&Align=center&Crop=Resize" alt="@p.GetPropertyValue("pageHeading")" title="@p.GetPropertyValue("pageHeading")">
</a>
<div class="detailed">
<h6 class="title-item">
<a href="@p.Url">@p.GetPropertyValue("pageHeading")</a>
</h6>
@if (p.GetPropertyValue<string>("salePrice") == "0")
<span class="price">TBA</span>
<span class="price">$@p.GetPropertyValue("salePrice")</span>
<div class="clear"></div>
<ul class="list-entry">
<li><b class="label">Reference:</b><span>@p.GetPropertyValue("propertyReference")</span></li>
<li><b class="label">Location:</b><span>@p.GetPropertyValue("suburb") @p.GetPropertyValue("state") </span></li>
<li><b class="label">Broker:</b><span> @Umbraco.RenderMacro("BrokerInfoById", new { BrokerId = bId.ToString() }) </span></li>
</ul><!--/ .list-entry-->
<a href="@p.Url" class="button orange">Details</a>
</div><!--/ .detailed-->
</article>
<div class="wp-pagenavi clearfix">
<div style="padding-bottom:10px;"><span class="pages">Page @page of @totalPages</span></div>
@for (int p = 1; p < totalPages + 1; p++)
var top1Cat = Request.QueryString["topCat"];
var subCat1 = Request.QueryString["subCat"];
var suburb1 = Request.QueryString["sub"];
string selected = (p == page) ? "selected" : string.Empty;
if (selected == "selected")
<span class="current">@p</span>
string strURL = "?page=" + p;
strURL = strURL + "&topCat=" + top1Cat;
strURL = strURL + "&sub=" + suburb1;
strURL = strURL + "&subCat=" + subCat1;
<a class="page" href="@strURL" title="Go to page @p of results">@p</a>
</div><!--/ .wp-pagenavi-->
if (articles.Count() == 0)
<p>There are no listings in this category</p>
Try this instead,
OrderBy(x => x.createDate)
how do i specify descending? OrderBy(x => x.createDate) with work ascending.
Are you still getting the same error though ?
Does the following work ? Or still having the macro error.
What happen if you remove Order ?
OrderByDescending(x => x.CreateDate.ToString())
is working on a reply...
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.
Continue discussion
OrderBy issue
Hi all
I am trying to order my list of nodes by createdate in decsending order. Here is my code that is failing:
IEnumerable<IPublishedContent> articles;
if (string.IsNullOrEmpty(suburb))
{
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderBy("createDate desc");
}
.OrderByDescending("createDate") ??
Nope, tried that too.
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending("createDate desc");
Fails.............
http://our.umbraco.org/forum/developers/razor/42030-Sort-by-price-razor
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending(x
=> x.createDate);
??
Hi hugh,
You should be able to apply the LINQ OrderByDescending() syntax for this query.
Hi Fuji
No, that still does not work. Causes a macro error.
Here is the code (inlcuding your orderby)
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Linq;
@{
var articleContainerId = 1067;
var topCat = Request.QueryString["topCat"];
var subCat = Request.QueryString["subCat"];
var suburb = Request.QueryString["sub"];
var categoryId = CurrentPage.Id.ToString();
var idToUse = string.Empty;
int pageSize = 25;
int page = 1; // The page we are viewing
if (!int.TryParse(Request.QueryString["page"], out page))
{
page = 1;
}
if (!string.IsNullOrEmpty(topCat))
{
idToUse = topCat;
}
if (!string.IsNullOrEmpty(subCat))
{
idToUse = subCat;
}
if (string.IsNullOrEmpty(idToUse))
{
idToUse = categoryId;
}
IEnumerable<IPublishedContent> articles;
if (string.IsNullOrEmpty(suburb))
{
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending(x=>x.CreateDate);
}
else
{
if (topCat == "1")
{
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue("suburb".ToUpper()).Equals(suburb.ToUpper()));
}
else
{
articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).Where(x => x.GetPropertyValue("suburb".ToUpper()).Equals(suburb.ToUpper()));
}
}
int totalNodes = articles.Count();
int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
if (page > totalPages)
{
page = totalPages;
}
else if (page < 1)
{
page = 1;
}
foreach (var p in articles.Skip((page - 1) * pageSize).Take(pageSize))
{
var advImgStr = p.GetPropertyValue<string>("photos").Split(',');
var selectedMedia = Umbraco.Media(advImgStr[0]);
var bId = p.GetPropertyValue("broker");
var strPrice = p.GetPropertyValue("salePrice");
var featureClass = "";
if (p.GetPropertyValue<bool>("isFeatured"))
{
featureClass = "background-color:#b7b8b8; padding:5px;";
}
<article style="@featureClass">
@if (p.GetPropertyValue<bool>("isFeatured"))
{
<p><strong>FEATURED AD</strong></p>
}
<a href="@p.Url" class="single-image picture">
<img src="/imageGen.ashx?image=@selectedMedia.umbracoFile&width=190&height=115&Align=center&Crop=Resize" alt="@p.GetPropertyValue("pageHeading")" title="@p.GetPropertyValue("pageHeading")">
</a>
<div class="detailed">
<h6 class="title-item">
<a href="@p.Url">@p.GetPropertyValue("pageHeading")</a>
</h6>
@if (p.GetPropertyValue<string>("salePrice") == "0")
{
<span class="price">TBA</span>
}
else
{
<span class="price">$@p.GetPropertyValue("salePrice")</span>
}
<div class="clear"></div>
<ul class="list-entry">
<li><b class="label">Reference:</b><span>@p.GetPropertyValue("propertyReference")</span></li>
<li><b class="label">Location:</b><span>@p.GetPropertyValue("suburb") @p.GetPropertyValue("state") </span></li>
<li><b class="label">Broker:</b><span> @Umbraco.RenderMacro("BrokerInfoById", new { BrokerId = bId.ToString() }) </span></li>
</ul><!--/ .list-entry-->
<a href="@p.Url" class="button orange">Details</a>
</div><!--/ .detailed-->
</article>
}
<div class="wp-pagenavi clearfix">
<div style="padding-bottom:10px;"><span class="pages">Page @page of @totalPages</span></div>
@for (int p = 1; p < totalPages + 1; p++)
{
var top1Cat = Request.QueryString["topCat"];
var subCat1 = Request.QueryString["subCat"];
var suburb1 = Request.QueryString["sub"];
string selected = (p == page) ? "selected" : string.Empty;
if (selected == "selected")
{
<span class="current">@p</span>
}
else
{
string strURL = "?page=" + p;
strURL = strURL + "&topCat=" + top1Cat;
strURL = strURL + "&sub=" + suburb1;
strURL = strURL + "&subCat=" + subCat1;
<a class="page" href="@strURL" title="Go to page @p of results">@p</a>
}
}
</div><!--/ .wp-pagenavi-->
if (articles.Count() == 0)
{
<p>There are no listings in this category</p>
}
}
Try this instead,
how do i specify descending? OrderBy(x => x.createDate) with work ascending.
Are you still getting the same error though ?
Does the following work ? Or still having the macro error.
What happen if you remove Order ?
is working on a reply...
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.