在模型中:
public DateTime? FromDate { get;set; }
在視圖中:
<div class="form-group">
<label class="label other">
From Date
</label>
<div class="col-md-10">
@Html.EditorFor(model => model.FromDate, new { htmlAttributes = new { @class = "form-control", type = "Date", min = "1944-01-01", max = "2019-01-01" } })
@Html.ValidationMessageFor(model => model.FromDate, "", new { @class = "text-danger" })
</div>
</div>
當我們從DateTime選擇器日歷中輸入日期時,它會輸入日期:

在Index視圖中它還顯示了時間:

問題是我不想在索引視圖中顯示時間和日期。
uj5u.com熱心網友回復:
要設定DateTime屬性型別的顯示格式,請使用DisplayFormat模型宣告中的屬性,如下所示:
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? FromDate { get; set; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/535864.html
上一篇:即使設定了[FromBody]和Content-Type,ControllerAction也不會使用JSFetchAPI接受JSONpost
