首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ASP.NET DisplayFormat dd/MM/yyyy不工作

ASP.NET DisplayFormat dd/MM/yyyy不工作
EN

Stack Overflow用户
提问于 2015-10-29 12:07:20
回答 4查看 6.2K关注 0票数 4

我的模型

代码语言:javascript
运行
复制
[Display(Name = "Tanggal Lahir")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime TanggalLahir { get; set; }

我的观点

代码语言:javascript
运行
复制
@Html.EditorFor(m => m.TanggalLahir)

但它仍然使用MM/dd/yyyy显示格式数据。

甚至是我的web.config

代码语言:javascript
运行
复制
<system.web>
  <globalization uiCulture="en" culture="en-GB"/>
  <authentication mode="None" />
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" maxRequestLength="30000000" />
</system.web>
EN

回答 4

Stack Overflow用户

发布于 2015-10-29 12:53:37

将属性声明为字符串

代码语言:javascript
运行
复制
[Display(Name = "Tanggal Lahir")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public string TanggalLahir { get; set; }
票数 1
EN

Stack Overflow用户

发布于 2015-10-29 12:26:03

代码语言:javascript
运行
复制
@Html.EditorFor(m => m.TanggalLahir, "{0:dd/MM/yyyy}", new {maxlength = 10})

你可以试试这样的东西..

票数 0
EN

Stack Overflow用户

发布于 2015-10-29 12:28:26

1如果你不能让它在模型上工作,你可以在视图上尝试它。

代码语言:javascript
运行
复制
 @Html.EditorFor(m => m.TanggalLahir, "{0:dd/MM/yyyy}", new {maxlength = 10})

(或)

代码语言:javascript
运行
复制
  @Html.EditorFor(m => m.TanggalLahir, new { @Value = Model.StartDate.ToString("dd/MM/yyyy") })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33405785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档