I have a modal dialog in my web application where users are able to enter a time range between 00:00 and 24:00. A range slider is used to select this range.
Everything works as expected except that whenever user sets the right range handle to have a value of 24:00 default model binder can’t parse this TimeSpan.
public class Timing
{
public TimeSpan Starts { get; set; }
public TimeSpan Ends { get; set; }
}
My object that gets sent back to server has an IList<Timing> property.
So. The problem is just that string value “24:00” can’t be parsed to TimeSpan instance. Is it possible to convince default model binder to recognise such string value?
I would like to avoid changing 24:00 on the client to 00:00. I know that I have Starts and Ends properties but my model validation validates that Ends is always greater than Starts. Manual changing to 23:59 is also cumbersome. Basically is it possible to pass 24:00 and still get parsed on the server.
I think the range is fractionally too large.
24:00is in fact00:00the next day.so they should go from
00:00.00to23:59.99or whatever.FINAL ANSWER(?) Change
24:00on the client to1.0:00.This will work because
TimeSpan.Parse("1.0:00").TotalHoursreturns24EDIT: See the documentation here: http://msdn.microsoft.com/en-us/library/se73z7b9.aspx. It shows the maximum range for days, hours, mins, etc. For hours it’s
0to23as per my comment below.EDIT: If you are just letting them choose an integer for hours, then parse it on the server.
eg.
TimeSpan ts = TimeSpan.FromHours(24)returns
1.00:00:00And of course you can always say
ts.TotalHoursand it returns24.