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 200 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 200 karma points
    Nov 19, 2014 @ 16:57
    jeff mayer
    0

    Is there any way to do this within a query?

  • Steve Morgan 1348 posts 4457 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 200 karma points
    Nov 20, 2014 @ 02:46
    jeff mayer
    0

    thank you much I'll give it a try

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x 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

Please Sign in or register to post replies

Write your reply to:

Draft