Reputation: 1603
How can i get the DateCreated field to auto populate with DateTime.Now
<div class="editor-label">
@Html.LabelFor(model => model.DateCreated)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateCreated)
@Html.ValidationMessageFor(model => model.DateCreated)
</div>
Upvotes: 0
Views: 97
Reputation: 102743
This is normally something you'd do outside of this scope of the view, ie, in the controller.
public ActionResult MyAction()
{
var model = new MyModel();
model.DateCreated = model.DateCreated ?? DateTime.Now;
return View(model);
}
Or, in the constructor of the model itself.
Upvotes: 2