Date Setting to 01/01/0001 00:00:00 in MVC 3.0 Web

2019-07-18 02:15发布

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条回答
Explosion°爆炸
2楼-- · 2019-07-18 02:52

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.

查看更多
登录 后发表回答