【发布时间】:2018-11-23 10:30:34
【问题描述】:
如何将日期格式设为"dd.MM.yyyy",因为无论我做什么,它总是"MM/dd/yyyy"
查看部分:
<div class="col-md-6 col-xs-6 pull-left">
<label asp-for="@Model.RequestRegistrationDateFrom"></label>
<div class="input-group date">
<input type="text" asp-for="@Model.RequestRegistrationDateFrom" class="form-control js-datepicker pull-left" />
<div class="input-group-append">
<span class="input-group-text calendar-fa"></span>
</div>
</div>
</div>
模型属性:
[BindProperty(SupportsGet = true)]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "dd.MM.yyyy")]
[Display(Name = "Date from", ResourceType = typeof(string))]
public DateTime? RequestRegistrationDateFrom { get; set; }
【问题讨论】:
-
[DataType(DataType.Date)]生成type="date"它将在浏览器文化中显示带有日期的浏览器 HTML5 日期选择器(您需要将ApplyFormatInEditMode = true添加到[DisplayFormat]并使用 ISO 格式 - 参考 @ 987654321@了解更多详情。 -
如果您不想要浏览器的 HTML5 日期选择器,则删除
[DataType]属性并将asp-format="{0:dd.MM.yyyy}"添加到<input> -
@StephenMuecke 这两种方法都不起作用:(
-
那你没做好或者还有其他问题
标签: c# asp.net-core-mvc