//首先,我选择Employee来编辑和更新Employee //
的详细信息[HttpGet]
public ActionResult Edit(int? employee_id)
{
Mapper.CreateMap<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>();//Mapping using AutoMapper
var dbContext = new MyDBDataContext();
var EmployeeDetails = dbContext.employees.FirstOrDefault(Employee => Employee.employee_id == employee_id);
var Employees = Mapper.Map<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>(EmployeeDetails);
return View(Employees);
}
//要编辑的代码//
[HttpPost]
public ActionResult Edit(employees employee1)
{
Mapper.CreateMap<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>(); //Mapping using AutoMapper
var dbContext = new MyDBDataContext();
var EmployeeDetails = dbContext.employees.FirstOrDefault(Employee => Employee.employee_id == employee1.employee_id);
TryUpdateModel(EmployeeDetails);
Mapper.Map<AutoMapperDemo.employee, AutoMapperDemo.Models.employees>(EmployeeDetails);
dbContext.SubmitChanges();
return RedirectToAction("Index");
}