我创建了一些表单,我需要在提交表单上指定字段CreationDate
:
@model Namespaces.Chapter
@using (Html.BeginForm ()) {
<p>Title: @Html.TextBoxFor(c => c.Title)</p>
...
@{ Model.CreationDate = DateTime.Now;} <- somehow like that, but this code does not works
<input type="submit" value="Submit" />
}
怎么做?
答案 0 :(得分:3)
在将控制器操作传递给数据访问之前,您必须在控制器操作中执行此操作,如:
public ActionResult SomeAction(SomeClass obj)
{
obj.CreationDate = DateTime.Now;
// your business logic goes here
................
................
}