Timespan not accepting day in MVC3

Posted by middelpat on Stack Overflow See other posts from Stack Overflow or by middelpat
Published on 2012-10-12T09:08:01Z Indexed on 2012/10/12 9:37 UTC
Read the original article Hit count: 187

Filed under:
|
|

I have a MVC3 application in which i want to set a timespan to for example 2 days and 5 hours. when i enter 02:05:00:00 it gives me the following exception:

System.OverflowException: SqlDbType.Time overflow.  Value '2.05:00:00' is out of range.  Must be between 00:00:00.0000000 and 23:59:59.9999999.

When i enter 05:00:00 it correctly saves 5 hours into the database. according to MSDN timespan has a property for days. How do i correctly set the days?

Model:

public class ProductionTimeVM
{        
    [Required]
    public TimeSpan DefaultTime { get; set; }
}

In my view i just use:

@Html.TextBoxFor(x => x.DefaultTime)

For my controller:

public ActionResult SaveProductionTime(ProductionTimeVM vm)
{           
   ProductionTime productionTime = new ProductionTime();
   productionTime.Default = vm.DefaultTime;

   //some more code
 }

Any idea's?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc-3