I want to create a simple ASP.Net form that will receive birth dates. I have a model with this property:
[DataType(DataType.Date)] public DateTime? BirthDate{ get; set; }
and, in my opinion (uses datepicker):
@Html.LabelFor(model => model.BirthDate) @Html.TextBoxFor(model => model.BirthDate, new { @class = "form-control date-picker" }) @Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" })
The only thing I installed on my javascript datepicker:
format: 'L'
because I want to show dates without times.
Now I can not save due to a validation error:
The value '12/23/2000' is not valid for BirthDate.
Now I KNOW his globalization error ... I need to set the culture in the <globalization> element in web.config, etc. But did you notice that I did not specify formats (except for the datepicker "L" format)? I want this form to give birth to people in any country, do not have a specific culture / format, etc.
Is it possible? How can i do this?
Edit:
- What date picker do you use?
JQuery, but this is not a requirement, I can switch to any datepicker that can easily handle various yyyy-mm-dd save formats and display format. - What locale is your server in and what format do you prefer to work in your MVC code and save to the database?
I do not know where my client will host the site, its AWS ... I prefer to work with en-us.
Click ok
source share