.Net DateTime 格式无法识别为参数 - 从 Javascript 调用
我有一个 MVC 操作方法,它采用 DateTime 作为参数。此操作由 Javascript 调用。
我无法让它识别日期和时间。我使用不变格式,例如 escape("2011/09/22 12:00:00") 但该值未在操作中绑定。
如果我只提供日期部分,例如 escape("2011/09/22"),则可以正常工作,但时间值也应该采用正确的格式,但它不受模型绑定器的约束......
I have a MVC action method which takes a DateTime as a parameter. This action is called from Javascript.
I can't get it to recognise dates with times. Im using an invariant format e.g. escape("2011/09/22 12:00:00") but this value isn't being bound in the action.
If I supply just the date part e.g. escape("2011/09/22"), that works OK but the value with the time should also be in a correct format but it isn't being bound by the model binder ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一个适合我的解决方案(并且可能以类似于 Sean 的答案的格式生成日期)...
我只是在 Javascript 中创建一个日期并将其作为数据发布为 Ajax 请求的一部分,
例如
结果是发布了以下格式的日期
被 MVC 的模型绑定接受。由于时间格式的原因,时间有所不同(我在澳大利亚)
I found a solution which works for me (and probably produces a date in a format similar to Sean's answer) ...
I just create a date in Javascript and posted this as data as part of an Ajax request
E.g.
resulted in a post of a date in the format of
which was accepted by MVC's model binding. The hour is different because of the time format (I'm in Australia)
我在将日期输入 ASP.NET Web 服务时遇到问题;我花了一段时间才找到所需的格式。但是一旦我找到它,我就有足够的信息来创建一个小的 stringify 类型的 js 函数:
I had problems getting dates into a asp.net webservice; took me a while to find out the format which was required. But once i found it i had enough information to create a small stringify-type js function:
尝试
try