I have a create method where I add a new Employee Object to the database, after the employee is added I want to go into the edit page to be able to enter more details about the employee if I wish.
The Edit action method takes 1 parameter, the EmployeeID, however this EmployeeID is dynamically assigned by the database once an object is added to the Employee Table. How do I access the ID of the newly added employee after _db.SaveChanges() within the same action method?
here is what part of my method looks like:
[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}); }