Not sure if this would work in Razor, but I've got something similar in an event handler I wrote - try using the DateTime.TryParse() on your ExpireDate parameter, with a proper DateTime variable as the outputted value (either from the conversion or from giving it a value on error using DateTime.MinValue).
The new variable should be in the right format to compare to DateTime.Now for your 'where' or 'if' conditions.
Thanks for the pointer, but this was about trying to filter on an empty date... I can't trap an error and give it a minValue either... as it doesn't give me an error...
reading up the current implementation of razor automatically correctly types dateTimes, so
expiredate > DateTime.Now, works as expected ;-)
Still trying to find a work around for the HasValue and IsNull in the where("") syntax returns unexpected results... as opposed to @item.param.HasValue and IsNull which work as expected.
even if ExpireDate on that node is empty HasValue() in the Where returns true... but then in the susequent iteration @item.HasValue("ExpireDate") tells me that some of the values contained in the node list actaully HasValue = False!
How to filter empty datetime picker in razor script?
I have an expiredate as a documentType parameter...
so I want to filter items that have expiredate < now... and also where the expiredate isn't set...
I can't seem to find a way to do that..
var items = node.Children.Where("expiredate > DateTime.Now || expiredate == False")
was my first guess... but that doesn't work...
although
var items = node.Children.Where("expiredate == False") does get all the ones with no dates set..
but var items = node.Children.Where("expiredate == False || expiredate == True") doesn't get all the items????
Any ideas?
forgot to add umb4.8 - (4.9/10 no good for me as content editor broken in medium trust)
Been banging my head against this on today....
thought I'd be able to leverage HasValue or isNull.... but nope..
This lists out all the children and gives correct true/false for when the expiredate has no value (DynamicNull)
However, using the where to try and filter for only those that have are null... gives no items :-( (same for the converse HasValue)
It's driving me insance that I can't do something this simple!
Not sure if this would work in Razor, but I've got something similar in an event handler I wrote - try using the DateTime.TryParse() on your ExpireDate parameter, with a proper DateTime variable as the outputted value (either from the conversion or from giving it a value on error using DateTime.MinValue).
The new variable should be in the right format to compare to DateTime.Now for your 'where' or 'if' conditions.
Thanks for the pointer, but this was about trying to filter on an empty date... I can't trap an error and give it a minValue either... as it doesn't give me an error...
reading up the current implementation of razor automatically correctly types dateTimes, so
expiredate > DateTime.Now, works as expected ;-)
Still trying to find a work around for the HasValue and IsNull in the where("") syntax returns unexpected results... as opposed to @item.param.HasValue and IsNull which work as expected.
In the end had to revert back to lambda expressions... and parsing strings into dates.... but clunky...
Crux of it seems to be that whilst
even if ExpireDate on that node is empty HasValue() in the Where returns true... but then in the susequent iteration @item.HasValue("ExpireDate") tells me that some of the values contained in the node list actaully HasValue = False!
is working on a reply...