我创建了一些表单,我需要在提交表单上分配字段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" />
}


怎么做?

最佳答案

您必须先在控制器操作中执行此操作,然后再将其传递给数据访问,例如:

public ActionResult SomeAction(SomeClass obj)
{
   obj.CreationDate = DateTime.Now;

   // your business logic goes here
   ................
   ................
}

10-08 16:37