[英]ASP.NET MVC 4: How to update model from view on submit form
I create some form and I need to assign field CreationDate
on submit form: 我创建了一些表单,我需要在提交表单上分配字段
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" />
}
How to do that? 怎么做?
You have to do this in the controller action before passing it to data access like: 您必须在控制器操作中执行此操作,然后将其传递给数据访问,如:
public ActionResult SomeAction(SomeClass obj)
{
obj.CreationDate = DateTime.Now;
// your business logic goes here
................
................
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.