Date Setting to 01/01/0001 00:00:00 in MVC 3.0 Web Application after submit button click

只谈情不闲聊 提交于 2019-12-24 01:39:09

问题


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.

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.

What is the solution ?

I have declared my datetime variable like this -

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

Is something missing in this ?

Technical Details :

I have deployed my MVC Application on Windows Server 2012 . Database is SQL Server 2012 and Web Server is IIS 8 .

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.

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 .

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

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.

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 .

Regards,

Mangesh


回答1:


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.

This is a problem of IIS 8.0 and newer.



来源:https://stackoverflow.com/questions/16055969/date-setting-to-01-01-0001-000000-in-mvc-3-0-web-application-after-submit-butt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!