单击提交按钮后,在MVC 3.0 Web应用程序中将日期设置为01/01/0001 00:00:00 [英] Date Setting to 01/01/0001 00:00:00 in MVC 3.0 Web Application after submit button click

查看:136
本文介绍了单击提交按钮后,在MVC 3.0 Web应用程序中将日期设置为01/01/0001 00:00:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为MVC Web应用程序设计了一个表单,用户可以使用该表单输入详细信息.详细信息之一是日期",他/她可以从日期时间选择器"中选择.

I have a designed a form for my MVC Web application with which the user can enter details . One of the details is Date which he /she can choose from a DateTime Picker.

输入包括日期在内的所有详细信息后,我提交了表单,但没有转到下一页,该表单重新加载,并且在日期"字段中设置了验证错误"并设置为01/01/0001 00:00:00作为日期.

After entering all the details including Date , I submit the form but instead of going to the next page, the same form reloads with a Validation Error on Date Field and setting 01/01/0001 00:00:00 as the Date.

有什么解决方案?

我已经这样声明了我的datetime变量-

I have declared my datetime variable like this -

[Required]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
public DateTime ShipmentDate { get; set; }

这个东西缺少什么吗?

技术细节:

我已经在 Windows Server 2012上部署了MVC应用程序.数据库是SQL Server 2012,Web服务器是IIS 8.

当我从开发版本运行时,它可以正常工作,即-从Visual Studio 2012- DB SQL Server 2012-IIS 7.5.但是上面一行是我要使用的实时版本.

When i run from my development version it is working fine ie - From Visual Studio 2012- Db SQL Server 2012 - IIS 7.5. But the above line is the live version which i want to work with.

请帮助您解决混乱问题.

Please help with the confusion.

一个可能的解决方案是上下文外的DateTimePicker文件.当我测试该应用程序时,请输入日期,例如:2013年4月17日.它起作用了.

One Possible solution can be the Out-of-context DateTimePicker File .When i tested the application, by entering the date eg: April 17, 2013.. it worked .

我为datetimePicker使用了一个外部.js文件.该文件的操作系统要求是Windows 7和Windows Vista.

I have used a external .js file for the datetimePicker. This file's OS requirements were Windows 7 , Windows Vista.

我已在Windows Server 2012上部署了我的应用程序(甚至服务器上的datepickerFile).因此,我认为该文件的JQuery Logic尚未实现,因此即使在表单的textBox中进行设置后,日期仍然为空.

I have deployed my application on Windows Server 2012 (even the datepickerFile on the server ) . Hence , I think , the file's JQuery Logic is not getting implemented and hence the date even after setting in the textBox of the form remains null.

最终,当我们执行回发时,会将null值返回到我的模型,并检查Model.IsValid的条件是否为null,这将失败,然后重新创建视图.由于Datetime的默认值为01/01/0001 00:00:00,因此该值会在dateTime字段中初始化.

Eventually, when we do a postback, the null value is returned to my model and the condition of Model.IsValid is checked for null ,which fails , and the view is recreated. Since, the default value of Datetime is 01/01/0001 00:00:00 , this value gets intialized in the dateTime field .

此致

Mangesh

推荐答案

在区域性信息不正确的情况下会发生这种情况,您需要配置web.conf

That happens when culture info is incorrect, you need to configure the web.conf

<system.web>    
    <globalization culture="en-US" />
</system.web>  

此处是来自您所在国家/地区的不同文化信息的列表.

here is a list of the different cultures info depend from the country you are.

这是IIS 8.0和更高版本的问题.

This is a problem of IIS 8.0 and newer.

这篇关于单击提交按钮后,在MVC 3.0 Web应用程序中将日期设置为01/01/0001 00:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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