Copied to clipboard

Flag this post as spam?

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


  • Mr A 216 posts 278 karma points
    Jul 11, 2012 @ 11:50
    Mr A
    0

    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");
            }

  • Mr A 216 posts 278 karma points
    Jul 11, 2012 @ 13:29
    Mr A
    0

    for instance for the month of august i tried this with no success:

     pagesToList @Model.NodeById(1078).Children.Where(DateTime.Parse("newsDate").Month == 8);

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 11, 2012 @ 14:38
    Michael Latouche
    0

    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.

  • Mr A 216 posts 278 karma points
    Jul 11, 2012 @ 15:06
    Mr A
    0

    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")

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 11, 2012 @ 15:17
    Michael Latouche
    0

    OK,

    This means that your newsDate property type is directly mapped to a DateTime then :-)

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft