Copied to clipboard

Flag this post as spam?

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


  • Brian McNally 13 posts 91 karma points
    May 29, 2014 @ 20:59
    Brian McNally
    0

    List Items greater than or equal to current datetime

    I'm sure this has to be a simple syntax problem but I just can't seem to get it working. I'm simply pulling a list of events and want to leave off any events occuring in the past. This is on a partial view macro file:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    @if (Model.MacroParameters["startNodeID"] != null) { @* Get the start node as a dynamic node *@ var startNode = Umbraco.Content(Model.MacroParameters["startNodeID"]);

    if (startNode.Children.Where("Visible").Any())
    {
    

    Upcoming Training

      @foreach (var page in startNode.Children.Where("Visible").OrderBy("startdate")) {
    • @page.Name
      @page.startdate.ToString("F")
    • }
    }    
    

    }

    I was hoping I could add some logic to the foreach loop but can't crack the syntax and can't find a good example online. If anyone could help out or point me in the right direction.

    thanks

  • Brian McNally 13 posts 91 karma points
    May 29, 2014 @ 21:04
    Brian McNally
    0

    Looks like the markdown editor jacked with the code. the part I was looking into was the foreach loop

    @foreach (var page in startNode.Children.Where("Visible").OrderBy("startdate"))
    

    How do i add another where statement saying that startdate needs to be greater than or equal to the current datetime

    thanks

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 29, 2014 @ 21:27
    Dennis Aaen
    1

    Hi Brian,

    Have you tried something like this:

    DateTime today = DateTime.Now;

    @foreach
    (var page in startNode.Children.Where("Visible").
    Where("startdate >= today").OrderBy("startdate")){

    }

    Hope this helps,

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 29, 2014 @ 21:34
    Jeavon Leopold
    100

    Very nearly Dennis,

    I think it needs to be like this

    DateTime today = DateTime.Now;
    
    @foreach(var page in startNode.Children.Where("Visible").Where("startdate >= @0", today).OrderBy("startdate")){
    
    }
    

    Jeavon

  • Brian McNally 13 posts 91 karma points
    May 29, 2014 @ 21:39
    Brian McNally
    0

    BAM....worked perfect..Thanks so much Jeavon

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 29, 2014 @ 21:55
    Jeavon Leopold
    0

    Awesome! You're very welcome Brian.

Please Sign in or register to post replies

Write your reply to:

Draft