In the back end I have a property with a regular text input box (definitely set as a Textstring type in the doc type).
In a razor script I have something that checks whether the field has been completed using !string.IsNullOrEmpty()
Hoverever, I have manually typed a time into this field (e.g. in the format 8:30am) and the razor is now failing because the text string has been converted into a dateTime object.
I can ToString() it back to a string, but is there anyway to prevent this from happening? I'd rather it was just treated as a string from the outset :)
Thanks Jeroen, your suggestion works, but is no different from just getting the property and calling ToString() on it, so it is still initially converted to a dateTime object.
The problem is that in this property there might just be a regular word, or there might be a string that refers to a time. So when there is a time, I just want the string, not the string version of a full dateTime object, e.g. if someone types in the field 8:30am, I want the string "8:30am" not the string "25/05/2001 08:30:00" which is what I am getting at the moment...
Interesting problem with razor
Hi all,
In the back end I have a property with a regular text input box (definitely set as a Textstring type in the doc type).
In a razor script I have something that checks whether the field has been completed using !string.IsNullOrEmpty()
Hoverever, I have manually typed a time into this field (e.g. in the format 8:30am) and the razor is now failing because the text string has been converted into a dateTime object.
I can ToString() it back to a string, but is there anyway to prevent this from happening? I'd rather it was just treated as a string from the outset :)
Many thanks
Dan
I think this is done automatically. See this post: http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5.
The best solution is probably to use Model.GetProperty("propName").Value since this will always return the result unchanged (and as a string).
Jeroen
Thanks Jeroen, your suggestion works, but is no different from just getting the property and calling ToString() on it, so it is still initially converted to a dateTime object.
The problem is that in this property there might just be a regular word, or there might be a string that refers to a time. So when there is a time, I just want the string, not the string version of a full dateTime object, e.g. if someone types in the field 8:30am, I want the string "8:30am" not the string "25/05/2001 08:30:00" which is what I am getting at the moment...
Any ideas?
I don't think you can disable the convert to datetime by default. Maybe ask Gareth Evans (@agrath) if he can add this to Umbraco 4.7.1.
Jeroen
is working on a reply...