【发布时间】:2021-10-19 12:23:24
【问题描述】:
我有一个 html 页面的给定模型来接受日期。我正在尝试将 datefrom 和 dateto 输入框格式化为 "dd/mm/yyyy" 格式。目前,它仅显示为文本格式。如何让两列都接受数据为 dd/mm/yyyy。
EditDateModel
public class EditDateModel
{
public string FromDate { get; set; }
public string ToDate { get; set; }
}
@model EditDateModel
<table id="tblEntry" class="table table-striped">
<thead>
<tr>
<th>Date From</th>
<th>Date To</th>
</tr>
</thead>
<tbody>
<tr>
<td>@Html.EditorFor(model => model.FromDate, new { htmlAttributes = new { @class = "form-control datepicker w-100" } })</td>
<td>@Html.EditorFor(model => model.ToDate, new { htmlAttributes = new { @class = "form-control w-100" } })</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
这能回答你的问题吗? Specify Date format in MVC5 (dd/MM/yyyy)
-
如果可以解决您的问题,您会检查我的答案吗?如果您遇到任何其他问题,请随时分享
-
为什么要使用字符串作为日期?您应该使用
DateTimes 和input type=date:mikesdotnetting.com/article/352/…
标签: c# asp.net-core razor-pages