0
我想在頁面加載時自動填充當前日期的文本框字段,並且仍然可以編輯它,但是當我放置'datetime.now'時,它似乎不起作用用當前日期填充日期時間視圖
這是我的看法:
<div class="form-group">
@Html.LabelFor(model => model.ReturnedDate, "Returned date", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReturnedDate,DateTime.Now.ToShortDateString()),new { htmlAttributes = new { @class = "box" } })
@Html.ValidationMessageFor(model => model.ReturnedDate)
</div>
</div>
剛剛成立ReturnedDate'的'價值在你的模型,你把它傳遞給視圖前(和使用'@ Html.TextBoxFor(M => m.ReturnedDate, 「{0:d}」,新{ @class =「box」})'來格式化它 –