用当前日期填充日期-时间视图



我想在加载页面时自动用当前日期填充文本框字段,并且仍然可以编辑它,但当我放置"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>

您需要将日期分配如下。

@Html.TextBoxFor(model => model.ReturnedDate, new { @Value = @DateTime.Now.ToShortDateString() })

最新更新