Hi,
I have nullable datetime (in UI and as date in DB) field for birth date. But when I click on Edit action in grid, It still displays as yyyy/MM/dd instead of yyyy-MM-dd. Hence I am getting BirthDay is not valid date error message. I have not written any explicit validation.
In my cshtml page I have formatted it as:
columns.Bound(r => r.BirthDay).Width(100).Format("{0:yyyy-MM-dd}");
In my model I have initialized as:
[Display(Name = "Birth Day")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? BirthDay { get; set; }
I can however generalized and apply formatting for my entire site by below code in global.asax but I want to apply it for specific pages only.
protected void Application_BeginRequest()
{
CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
info.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
System.Threading.Thread.CurrentThread.CurrentCulture = info;
}
Please help!
Thanks,
Nirav
I have nullable datetime (in UI and as date in DB) field for birth date. But when I click on Edit action in grid, It still displays as yyyy/MM/dd instead of yyyy-MM-dd. Hence I am getting BirthDay is not valid date error message. I have not written any explicit validation.
In my cshtml page I have formatted it as:
columns.Bound(r => r.BirthDay).Width(100).Format("{0:yyyy-MM-dd}");
In my model I have initialized as:
[Display(Name = "Birth Day")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? BirthDay { get; set; }
I can however generalized and apply formatting for my entire site by below code in global.asax but I want to apply it for specific pages only.
protected void Application_BeginRequest()
{
CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
info.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
System.Threading.Thread.CurrentThread.CurrentCulture = info;
}
Please help!
Thanks,
Nirav