Server Location Date Format is being ignored when sending date to Http GEt parameter
My Station is configu开发者_开发问答red to EU Location format for date: dd/mm/yyyy Everything is working fine expect when I send a date as a parameter via HTTP get:
http://localhost:6105/assignment?date=07/02/2011
This call is received by this code:
public ActionResult Index(DateTime? date = null)
{
}
as date = 2.7.2011
any other date reference in the site is working OK and as expected (dd/mm/yyyy).
How can I resolve this ?
I had the same issue as you and found the solution at this site: Localization of dates in asp.net. The issue is that MVC does not support localization of DateTimes in GET-requests, only in POST-requests. This is by design! The blog post mentions some javascript-hacks to avoid this issue but I'd change to use culture-invariant dates.
I know it's been 2 years but I used this method :
I pass the parameter as a string and parse it to a DateTime in the backend code :
public ActionResult Index(string date = null)
{
DatetTime realDate;
DateTime.TryParse(date, out realDate)
}
精彩评论