Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
View Model
C#
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
[Required(ErrorMessage = "*")]
public DateTime? TransferDate { get; set; }

Javascript
JavaScript
$("#TransferDate").datepicker({ dateFormat: 'mm/dd/yy' });

View
HTML
@Html.EditorFor(model => model.TransferDate)

Although I have also change the culture information in Web.Config,Reference to this post post
HTML
<globalization uiCulture="en-US" culture="en-US"/>

But still validation is coming false,validation error is The value '11/21/2014' is not valid for TransferDate
In controller, ModelState.IsValid is false,TransferDate value is coming null.

please suggest me some Solution.
Posted
Updated 24-Nov-14 21:22pm
v2
Comments
Zoltán Zörgő 30-Nov-14 7:54am    
Any progress? If you have found my answer of use, feel free to accept it!

You might need to put a ModelBinder in place.
See: http://weblogs.asp.net/melvynharbour/mvc-modelbinder-and-localization[^]
http://stackoverflow.com/questions/7889038/asp-net-mvc-datetime-culture-issue-when-passing-value-back-to-controller[^]

But you'r right, DataAnnotation based validation should be culture-aware. But it looks you have done everything as you should. Still, I can imagine that there is a neater solution for this...
 
Share this answer
 
Replace in View

@Html.EditorFor(model => model.TransferDate)

to

<input type="text" name = "TransferDate" id="TransferDate" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900