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 , i am passing a querystring which is month , for filteration of news section but i am struggling with the razor syntax for it , below is the code , any suggestion or assistance will be highly appreciated:
@inherits umbraco.MacroEngines.DynamicNodeContext@{ var month = HttpContext.Current.Request.QueryString["month"]; var pagesToList = @Model.NodeById(1008).Children.OrderBy("newsDate desc"); if(@month == "jan") { pagesToList = @Model.NodeById(1078).Children.Where()OrderBy("newsDate"); } else if(@month == "feb"){ pagesToList = @Model.NodeById(1078).Children.Where().OrderBy("newsDate"); }
else { pagesToList = @Model.NodeById(1078).Children.OrderBy("newsDate desc"); }
for instance for the month of august i tried this with no success:
pagesToList = @Model.NodeById(1078).Children.Where(DateTime.Parse("newsDate").Month == 8);
Hi,
I found this thread referring to a similar issue I think : http://our.umbraco.org/forum/developers/razor/26022-Razor,-Where-%28DatetTime-Greater-Than-Or-Equal-DateX-%29
A far as I understand correctly, the following should work:
pagesToList = @Model.NodeById(1078).Children.Where("DateTime.Parse(\"newsDate\").Month == 8")
Hope this helps.
Cheers,
Michael.
I tried the following code which is working , i have no idea how but its returning the correct results:
pagesToList = @Model.NodeById(1078).Children.Where("newsDate.Month == 7");
OK,
This means that your newsDate property type is directly mapped to a DateTime then :-)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to filter the result by month in Razor
Hi , i am passing a querystring which is month , for filteration of news section but i am struggling with the razor syntax for it , below is the code , any suggestion or assistance will be highly appreciated:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var month = HttpContext.Current.Request.QueryString["month"];
var pagesToList = @Model.NodeById(1008).Children.OrderBy("newsDate desc");
if(@month == "jan")
{
pagesToList = @Model.NodeById(1078).Children.Where()OrderBy("newsDate");
}
else if(@month == "feb"){
pagesToList = @Model.NodeById(1078).Children.Where().OrderBy("newsDate");
}
else {
pagesToList = @Model.NodeById(1078).Children.OrderBy("newsDate desc");
}
for instance for the month of august i tried this with no success:
pagesToList = @Model.NodeById(1078).Children.Where(DateTime.Parse("newsDate").Month == 8);
Hi,
I found this thread referring to a similar issue I think : http://our.umbraco.org/forum/developers/razor/26022-Razor,-Where-%28DatetTime-Greater-Than-Or-Equal-DateX-%29
A far as I understand correctly, the following should work:
Hope this helps.
Cheers,
Michael.
I tried the following code which is working , i have no idea how but its returning the correct results:
pagesToList = @Model.NodeById(1078).Children.Where("newsDate.Month == 7");
OK,
This means that your newsDate property type is directly mapped to a DateTime then :-)
Cheers,
Michael.
is working on a reply...