使用全球化设置覆盖 mvc 3 中的日期格式
我有一个使用 razor 的 mvc 网站,其中全球化设置为自动,并且使用客户首选的文化。
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />
我想知道是否有一种方法可以强制通过剃刀绑定的日期以特定格式显示而忽略文化?
例如,如果我有一个模型
public class someObj
{
public DateTime someDateTime { get; set; }
}
并且我在视图中像这样绑定它:
@Model.someDateTime
我可以覆盖浏览器想要的首选区域性吗?
提前致谢。
I have a mvc website using razor where the globalization is set to auto and it is using the clients preferred culture.
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />
What I'd like to know is there a way to force a date that is being bound via razor to show in a specific format ignoring the culture?
For example if I have a model
public class someObj
{
public DateTime someDateTime { get; set; }
}
And I bind it like so in the view:
@Model.someDateTime
Can I override the preferred culture that the browser wants?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用 @Model.SomeDate.ToString("Some Format", new CultureInfo(...))
Call
@Model.SomeDate.ToString("Some Format", new CultureInfo(...))