年,月,日和参数描述了一个未再presentable的DateTime异常 [英] Year, Month, and Day parameters describe an un-representable DateTime Exception

查看:1505
本文介绍了年,月,日和参数描述了一个未再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.

这篇关于年,月,日和参数描述了一个未再presentable的DateTime异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆