gpt4 book ai didi

c# - ASP.NET MVC 4 : How to update model from view on submit form

转载 作者:太空宇宙 更新时间:2023-11-03 23:21:24 27 4
gpt4 key购买 nike

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

怎么做?

最佳答案

在将其传递给数据访问之前,您必须在 Controller 操作中执行此操作,例如:

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

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

关于c# - ASP.NET MVC 4 : How to update model from view on submit form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35321403/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com