This is a migrated thread and some comments may be shown as answers.

TimeSpan, Ajax binding & EditorFor

2 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 27 Apr 2013, 08:48 AM
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 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 01 May 2013, 10:30 AM
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!
0
Richard
Top achievements
Rank 1
answered on 01 May 2013, 10:42 AM
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
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Richard
Top achievements
Rank 1
Share this question
or