Copied to clipboard

Flag this post as spam?

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


  • jeff mayer 122 posts 199 karma points
    Nov 17, 2014 @ 18:09
    jeff mayer
    0

    Adding condition to filter records in where statement

    Have an existing razor loop that retrieves  events  based on date. I need to fliter requests bases on event type in the query.   

     

    Existing query:

    var nodes = root.Descendants("CalendarItem").OrderBy("CalendarEventDayTimeStart").Where("CalendarEventDayTimeStart >= DateTime.Now.Date"  );

    I need to filter using the value from a radio button:

     

    I have used the following which works but not within the query above. Can this be combined to  limit records based on the event type  radio value? I don't want to include a nested if statement. I need to include within the initial query. 

    if ( Umbraco.GetPreValueAsString(CurrentPage.eventtype) == "conference" ) 

     

     

     

     

  • jeff mayer 122 posts 199 karma points
    Nov 19, 2014 @ 16:57
    jeff mayer
    0

    Is there any way to do this within a query?

  • Steve Morgan 1278 posts 4216 karma points c-trib
    Nov 19, 2014 @ 18:40
    Steve Morgan
    1

    Hi,

    The radio box stores an integer values that relates to the text values that you've set as the data type. 

    Something like this should work....

    var nodes = root.Descendants("CalendarItem").OrderBy("CalendarEventDayTimeStart").Where("CalendarEventDayTimeStart >= DateTime.Now.Date && eventtype == 44"  );

     

    Replace 44 for the int value of your radio field. You might want to do a quick test output in your loop to find out the int values or just inspect the control in the back end using your browser tools of choice.  

  • jeff mayer 122 posts 199 karma points
    Nov 20, 2014 @ 02:46
    jeff mayer
    0

    thank you much I'll give it a try

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Nov 20, 2014 @ 12:12
    Jeroen Breuer
    0

    Hello,

    These query examples are for when you are using dynamic objects. It's recommended to use strongly typed objects. For example: http://our.umbraco.org/documentation/Reference/Mvc/querying

    Jeroen

  • 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.

Please Sign in or register to post replies