ASP.NET MVC 3 不接受我的德语日期格式设置 - 为什么?
我有一个新的 ASP.NET MVC 3 项目,MVC 和 Razor 对我来说都是全新的......无法弄清楚这个。
我有一台美式英语 Win7 x64 的开发机器,运行英语版本的 VS 2010 Pro SP1 和 ASP.NET MVC 3。但是我正在开发的应用程序适用于本地客户端,并且需要全部为德语并使用此处常用的所有格式和默认值。
在我的视图模型中,我定义了一个 DateTime
类型的变量,并用一些关于如何显示(和编辑)它的额外提示来增强它 - 我需要瑞士-德国日期格式,即: day.month.year
(按照该顺序,用点 .
分隔 - 而不是斜杠)
public class MyViewModel
{
[Display(Name = "Gültig am")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString="dd.MM.yyyy", ApplyFormatInEditMode=true)]
public DateTime ValidAt { get; set; }
}
(当然,该视图模型中有更多属性,但这些不是刚才相关)
在我的 Razor 视图中,我只需使用ASP.NET MVC 3 Add View
T4 模板设置的默认内容:
@Html.EditorFor(model => model.ValidAt)
问题是:如果我输入类似 13.06.2011
(2011 年 6 月 13 日)的内容相信是有效的并且符合我的显示和编辑格式,但我仍然收到客户端验证,指出值“13.06.2011”无效
- 为什么???
一定有一些非常基本的东西(可能完全是愚蠢的)我在这里错过了......
即使我已经设置了所有这些,
I have a new ASP.NET MVC 3 project, and MVC and Razor are all brand new to me... can't figure this one out.
I have a dev machine on US-English Win7 x64, running English versions of VS 2010 Pro SP1 and ASP.NET MVC 3. But the app I'm working on is for a local client, and needs to be all in German and use all the formatting and defaults commonly used here.
In my view model, I have defined a variable of type DateTime
and augmented it with some extra hints as to how to display (and edit) it - I need the Swiss-German date formatting, which is: day.month.year
(in that order, separated by dots .
- not slashes)
public class MyViewModel
{
[Display(Name = "Gültig am")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString="dd.MM.yyyy", ApplyFormatInEditMode=true)]
public DateTime ValidAt { get; set; }
}
(of course, there are more properties in that view model, but those aren't relevant just now)
In my Razor view, I simply use the default stuff set up by the ASP.NET MVC 3 Add View
T4 template:
@Html.EditorFor(model => model.ValidAt)
Trouble is: if I enter something like 13.06.2011
(13th of June, 2011) which I believe is valid and conforming to my display and editing formats, I am still getting a client-side validation saying that The value '13.06.2011' is invalid
- WHY???
There must be something really fundamental (and probably totally silly) that I'm missing here....
Even though I have set all of this up,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用什么进行客户端验证?您是否看过 组合验证方法jQuery 验证插件用“or”代替“and”?
What do you use for client validation? Did you look at Combining validation methods in jQuery Validation plugin with "or" instead of "and" ?