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" )
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.
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.
Is there any way to do this within a query?
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.
thank you much I'll give it a try
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
is working on a reply...