Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan Wellman 20 posts 40 karma points
    May 25, 2011 @ 10:23
    Dan Wellman
    0

    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

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    May 25, 2011 @ 10:30
    Jeroen Breuer
    0

    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

  • Dan Wellman 20 posts 40 karma points
    May 25, 2011 @ 11:03
    Dan Wellman
    0

    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?

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    May 25, 2011 @ 11:05
    Jeroen Breuer
    0

    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies