Reputation: 2472
I have a Kendo Grid that has a EditorTemplate with a timepicker in it. The timepicker works great and the Time displays on the grid fine, but when I try to save it is erroring saying the value isn't correct for the object. Below is my code. When I hit save it tells errors saying "The value '2/24/2014 07:00:00 AM' is not valid for Brief. The time is the time I selected from the timepicker. How do I just send the Time only without the date, or what is the best option to save the Time only to the database?
ViewModel (Partly):
[UIHint("_TimePicker")]
public TimeSpan? Brief { get; set; }
[UIHint("_TimePicker")]
public TimeSpan? KickOff { get; set; }
[UIHint("_TimePicker")]
public TimeSpan? Debrief { get; set; }
Grid:
@(Html.Kendo().Grid<Optic_Freedom.Areas.Scheduling.Models.ExerciseBreakdownViewModel>()
.Name(string.Format("Grid"))
.Columns(columns =>
{
columns.Bound(p => p.Personnel.Name).Width(100);
columns.Bound(p => p.NumberOfTeams).Width(80);
columns.Bound(p => p.TeamMembers).Width(100);
columns.Bound(p => p.Vehicles).Width(100);
columns.Bound(p => p.Brief).Format("{0:HH:mm}").EditorTemplateName("_TimePicker1").Width(100);
columns.Bound(p => p.KickOff).Format("{0:HH:mm}").EditorTemplateName("_TimePicker2").Width(100);
columns.Bound(p => p.Debrief).Format("{0:HH:mm}").EditorTemplateName("_TimePicker3").Width(100);
})
EditorTemplate:
@using Kendo.Mvc.UI
@model TimeSpan?
@(Html.Kendo().TimePickerFor(m=>m)
.Value(@Model.GetValueOrDefault())
.Min("06:00")
.Max("22:00")
.Format("{0:HH:mm}"))
Upvotes: 1
Views: 2614
Reputation: 356
It looks like you need to store it in a DateTime structure and parse the time out of it. TimeSpan is for storing a length of time (e.g. 35 mins), rather than a specific time of day (11:30 EST). Jon Skeet discusses his Noda Time library in a related answer which may help.
Upvotes: 1