TimeSpan, Ajax binding & EditorFor

3 posts, 0 answers
  1. Richard
    Richard avatar
    13 posts
    Member since:
    Sep 2007

    Posted 27 Apr 2013 Link to this post

    Hi,

    I have an mvc4 project with entity framework 4.1 and a data model with a timespan, which I need to bind to a grid and update, via Ajax, using a time picker in an editor template, in grid popup edit mode.

    I can format the timespan to display correctly on read, but on edit I just cannot work out the right pattern.  I understand the issue is due to how Json deals with timespans.   This seems to be an issue which is causing a few some big headaches, so I would like to ask for a recommended pattern for binding to a timespan and a code example please.

    Thanks
    Rich
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 01 May 2013 Link to this post

    Hi Richard,

     
    Basically editing of TimeSpan object using TimePickers is not directly related to KendoUI (the TimeSpan object represents period using ticks but the TimePickers are expecting Date object as value), but is a general programming task. There are several ways to do that and which one you would choose depends entirely on you and on the exact setup that you have – more information on this matter is available in various resources on the Internet. For example if the TimeSpan is expected to be set to maximum 24h you can create ViewModel which to contain DateTime field. Then you can convert the TimeSpan to DateTime on the server - for example the period can be calculated based on given date with time information 00h:00m:00s to the one selected currently in this field.

    Kind Regards,
    Vladimir Iliev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Richard
    Richard avatar
    13 posts
    Member since:
    Sep 2007

    Posted 01 May 2013 Link to this post

    Thanks for the clarification Vladimir,

    I thought I had read in the documentation that TimeSpan is directly supported.   If the answer is convert to DateTime then fine.

    Thanks
    Rich
Back to Top