这是模型:
public class Test
{
[Key]
public int Id{ get; set; }
public string Serial{ get; set; }
public string Name{ get; set; }
}
使用帖子进行编辑
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Id,Name")] Test test)
{
if (ModelState.IsValid)
{
db.Entry(test).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(test);
}
如果您发现编辑帖子上没有串行绑定,那么我的序列空白或空白
答案 0 :(得分:1)
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Id,Name,Serial")] Test test)
{
if (ModelState.IsValid)
{
db.Tests.Attach(test); //Tests is your controller i guess
db.Entry(test).Property(x => x.Name).IsModified = true;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(test);
}