【发布时间】:2016-01-05 00:46:27
【问题描述】:
我似乎遗漏了一些明显的东西。我在编辑方法中使用 Bind 仅更新 Bind 中列出的字段。但是,所有字段都在更新,并且由于许多字段未包含在表单帖子中,因此这些字段被覆盖并设置为 null。我只想更新 Bind 中列出的字段。
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit([Bind(Include = "customerid,firstname,lastname,businessid,userid")] customers customers)
{
if (ModelState.IsValid)
{
db.Entry(customers).State = EntityState.Modified;
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
...
}
【问题讨论】:
标签: c# asp.net-mvc entity-framework