年,月,日和参数描述了一个未再presentable的DateTime异常

问题描述:

我用下面的code,但该对象的属性之一是给我的困难添加对象到ASP.NET MVC 3应用程序中的列表。

I'm adding an object to a list within an ASP.NET MVC 3 application using the following code but one of the properties of the object is giving me difficulties.

ls.Add(new UserRoleModel { UserRoleId = 1, UserName = "Paul", InsertDate = new DateTime(05, 24, 2012),InsertProgram="sqlplus",InsertUser="sp22",Role="Implementation Co-corindator"});

此建立,但是当我去到相应的页面我得到以下类型的异常:

This builds but when I go to the relevant page i get an Exception with the following type:

Exception Details: System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.

我试过在本月去除0,但我得到了同样的异常。

I've tried removing the 0 in the month but I get the same exception.

的DateTime constructor您呼叫接受订单年,月,日的参数。

The DateTime constructor you are calling accepts parameters in the order year, month, day.

您在订单月,日,一年为他们提供。该文件是在允许值是什么pretty清楚,如果你通过2012年天的价值会发生什么。

You are providing them in the order month, day, year -- which ends up trying to assign meaningless values. The documentation is pretty clear on what the allowed values are and what happens if you pass 2012 for the "day" value.