I'm referring to below link: stackoverflow.com/questions/18288675/display-datetime-value-in-dd-mm-yyyy-format-in-mvc4
Your model
[Required(ErrorMessage = "Enter the Issued date.")]
[DataType(DataType.Date)]
public DateTime IssueDate { get; set; }
Razor Page
@Html.TextBoxFor(model => model.IssueDate)
@Html.ValidationMessageFor(model => model.IssueDate)
Jquery DatePickter
$(document).ready(function () {
$('#IssueDate').datepicker({
dateFormat: "dd/mm/yy",
showStatus: true,
showWeeks: true,
currentText: 'Now',
autoSize: true,
gotoCurrent: true,
showAnim: 'blind',
highlightWeek: true
});
});
Webconfig File
<system.web>
<globalization uiCulture="en" culture="en-GB"/>
</system.web>
It works when using date format dd/MM/yyyy like 3/5/2015 but wont work when using date like 29/5/2015.
The textbox will show 29/5/2015 once we selected date from jquery datepicker. Just that when it post back to server, the model will show that the date is null (I'm using DateTime?). It will work just fine with 3/5/2015...
Any help?
EDIT:
I add below to my controller. When I postback, the function below will execute and it is showing en-GB. Then it will enter my other Action that suppose to handle the httppost, but it is showing en-US!
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
const string culture = "en-GB";
CultureInfo ci = CultureInfo.GetCultureInfo(culture);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
}