您好我正在为学校构建一个Web应用程序。 我正在尝试更新学生信息,我已经做过教师部分
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Save(Teacher teacher)
{
if (!ModelState.IsValid)
{
var data = teacher;
return View("TeacherForm", data);
}
if (teacher.Id == 0)
_context.Teachers.Add(teacher);
else
{
var dataInDb = _context.Teachers.Single(c => c.Id == teacher.Id);
dataInDb.Name = teacher.Name;
dataInDb.Designation = teacher.Designation;
dataInDb.EducationalQualification = teacher.EducationalQualification;
dataInDb.DateOfBirth = teacher.DateOfBirth;
dataInDb.PhoneNumber = teacher.PhoneNumber;
dataInDb.StartDate = teacher.StartDate;
dataInDb.EndDate = teacher.EndDate;
dataInDb.Status = teacher.Status;
}
_context.SaveChanges();
return RedirectToAction("Index", "Teacher");
}
但是在学生部分我想使用自动映射器来获取地图数据
if (student.Id == 0)
_context.Students.Add(student);
else
{
var dataInDb = _context.Students.Single(c => c.Id == student.Id);
Mapper.Map(student, dataInDb);
}
但它不起作用。我尝试编辑数据,但表数据保持不变。 它的接力难以为学生写出每一处房产。 我怎么解决这个问题?