【发布时间】:2015-02-14 19:13:59
【问题描述】:
我有一个 create 方法,我在数据库中添加一个新的员工对象,添加员工后,我想进入编辑页面,如果我愿意,可以输入有关员工的更多详细信息。
Edit 操作方法采用 1 个参数,即 EmployeeID,但是一旦将对象添加到 Employee 表中,该 EmployeeID 就会由数据库动态分配。如何在同一操作方法中访问_db.SaveChanges() 后新添加员工的ID?
这是我的方法的一部分:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Employee Employee) {
_db.Employees.Add(Employee);
_db.SaveChanges();
//access the employee and gets its id???
//var id = id???
return RedirectToAction("EditEmployeeViewModel", new { id = id});
}
【问题讨论】:
标签: c# mysql .net asp.net-mvc entity-framework