问题描述
是否可以借助 中的
?我尝试通过在 HTML Helper
方法以 dd/mm/yyyy 格式显示 DateTime
值Asp.NET MVC@Html.LabelFor
中使用一些格式并向相关属性添加一些注释来做到这一点,如下所示,但这没有任何意义.任何解决此问题的帮助将不胜感激.
Is it possible to display a DateTime
value in dd/mm/yyyy format with the help of HTML Helper
methods in Asp.NET MVC
? I tried to do this by using some formats in @Html.LabelFor
and adding some annotations to the related property like below but it does not make any sense. Any help to solve this problem would be appreciated.
型号:
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> RegistrationDate { get; set; }
推荐答案
经过几个小时的搜索,我用几行代码就解决了这个问题
After few hours of searching, I just solved this issue with a few lines of code
您的模型
[Required(ErrorMessage = "Enter the issued date.")]
[DataType(DataType.Date)]
public DateTime IssueDate { get; set; }
剃刀页面
@Html.TextBoxFor(model => model.IssueDate)
@Html.ValidationMessageFor(model => model.IssueDate)
Jquery DatePicker
<script type="text/javascript">
$(document).ready(function () {
$('#IssueDate').datepicker({
dateFormat: "dd/mm/yy",
showStatus: true,
showWeeks: true,
currentText: 'Now',
autoSize: true,
gotoCurrent: true,
showAnim: 'blind',
highlightWeek: true
});
});
</script>
网络配置文件
<system.web>
<globalization uiCulture="en" culture="en-GB"/>
</system.web>
现在您的文本框将接受dd/MM/yyyy"格式.
Now your text-box will accept "dd/MM/yyyy" format.
这篇关于在 Asp.NET MVC 中以 dd/mm/yyyy 格式显示日期时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!