使用 ASP.NET MVC4,我有一个 CreateView,用户在其中指定作者、文本和 CreateTime。我不希望用户看到或填写 CreateTime,我希望我的代码在这里使用DateTime.Now.ToShortDateTime()
.
这是我想机会的 CreateView 中的这一部分。
@Html.EditorFor(model => model.CreateTime)
编辑:这是我的 CreateView:
@model Models.Topic
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Topic</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Author)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Author)
@Html.ValidationMessageFor(model => model.Author)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CreateTime)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CreateTime)
@Html.ValidationMessageFor(model => model.CreateTime)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}