I have an application that warrants the need for users to supply a "best fit time of day" for a particular day of week. I am trying to represent that time of day as the timespan object in C# (just as the DateTime.TimeOfDay object does) I don't need the date, but also don't want to use datetime and have the user see an actual date.
Right now i have this in my model:
[Required, Display(Name = "Start")]
public TimeSpan StartTime { get; set; }
[Required, Display(Name = "End")]
public TimeSpan EndTime { get; set; }
I have this for part of my view:
<div class="form-group col-xs-6 col-lg-4">
@Html.LabelFor(m => m.StartTime, new { @class = "control-label" })
@(Html.Kendo().TimePickerFor(m => m.StartTime).Interval(15).Culture("en-Us").HtmlAttributes(new { @class = "form-control" }))
@Html.ValidationMessageFor(m => m.StartTime)
</div>
<div class="clearfix"></div>
<div class="form-group col-xs-6 col-lg-4">
@Html.LabelFor(m => m.EndTime, new { @class = "control-label" })
@(Html.Kendo().TimePickerFor(m => m.EndTime).Interval(15).Culture("en-Us").HtmlAttributes(new { @class = "form-control" }))
@Html.ValidationMessageFor(m=>m.EndTime)
</div>
<div class="clearfix"></div>
I keep getting this model error using the MVC ModelState:
ErrorMessage = "The value '1:00 PM' is not valid for Start."
I'm not sure what i'm doing wrong, intellesense says that the kendo widget supports a timespan for it's input, but why isn't this actually binding to the view?
i have seen this article: Kendo Timepickerfor formatting not working
It's not quite what i'm looking for, because i feel like there should be a more simple way to represent a time of the day that is unrelated to the actual date... Any help is greatly appreciated!
Thanks!
Using DateTime seemed to work like you had said @Saranga
Not too thrilled it stores the entire date in the database, as it's not immediately clear then that this is only relevant to the time only, but it works.
Thanks for your help!