将日期发送到 Http GEt 参数时,服务器位置日期格式被忽略
我的工作站已配置为日期的欧盟位置格式:dd/mm/yyyy 一切正常,期望当我通过 HTTP get 发送日期作为参数时:
http://localhost:6105/assignment?date=07/02/2011
此代码接收此调用:
public ActionResult Index(DateTime? date = null)
{
}
as date = 2.7.2011
站点中的任何其他日期引用都工作正常且符合预期 (dd/mm/yyyy )。
我该如何解决这个问题?
My Station is configured 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了与您相同的问题,并在此站点找到了解决方案: asp.net 中的日期本地化。问题是 MVC 不支持 GET 请求中日期时间的本地化,仅支持 POST 请求中的日期时间本地化。这是设计使然!
博客文章提到了一些 javascript-hacks 来避免这个问题,但我会改为使用文化不变的日期。
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.
我知道已经过去了 2 年,但我使用了这个方法:
我将参数作为字符串传递,并在后端代码中将其解析为 DateTime:
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 :