【发布时间】:2016-12-29 19:34:20
【问题描述】:
我正在 MVC 中进行 CRUD 操作。我也在使用实体框架。我只向用户显示表的 12 个值(还有 currenttime(createDateTime) 值,用户在创建之前无法看到)。当我单击创建按钮时。 它应该保存我在编辑器字段中写入的所有值,并将当前时间保存到数据库。
创建视图
<div class="form-group">
@Html.LabelFor(model => model.languageID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.languageID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.languageID, "", new { @class = "text-danger" })
</div>
</div>
控制器
[HttpPost][ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "pkID,projectID,languageID,projectCompany,projectTitle,projectLink,projectText,projectImageURL,isPassive,createDateTime,createUsername,updateDateTime,updateUsername")] cusContentProjects cusContentProjects)
{
if (ModelState.IsValid)
{
db.cusContentProjects.Add(cusContentProjects);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(cusContentProjects);
}
【问题讨论】:
标签: c# html entity-framework model-view-controller crud