Razor - Textstring evaluated as DateTime (sometimes)
I have a field which I use to store the Hours for an event. As it may list just a starting time or a range I used a separate Text field instead of a DatePicker with Time. When trying to pull the field in Razor, if it just has a starting time (e.g. 8am) it treats it like a DateTime field with today's date and that time. If it has a range (i.e. 8am - 4pm) it treats it like a textstring (as I desire). I currently have to account for this with the following code:
It's a feature called ducktyping ("if it walks like a duck and it talks like a duck, it must be a duck"). So if something looks like a datetime, it must be one.
You can overcome this by doing: @item.GetProperty("meetingTime").Value
The Value of the GetProperty method always returns a string.
Razor - Textstring evaluated as DateTime (sometimes)
I have a field which I use to store the Hours for an event. As it may list just a starting time or a range I used a separate Text field instead of a DatePicker with Time. When trying to pull the field in Razor, if it just has a starting time (e.g. 8am) it treats it like a DateTime field with today's date and that time. If it has a range (i.e. 8am - 4pm) it treats it like a textstring (as I desire). I currently have to account for this with the following code:
What I want to know is this a feature, a bug or a little of both?
Thanks.
--Chris
It's a feature called ducktyping ("if it walks like a duck and it talks like a duck, it must be a duck"). So if something looks like a datetime, it must be one.
You can overcome this by doing: @item.GetProperty("meetingTime").Value
The Value of the GetProperty method always returns a string.
Thanks for the workaround and the info. Definitely something to be aware of when using Razor.
--Chris
is working on a reply...