I have this function in my controller.
[HttpPost]
public ActionResult Edit(EmployeesViewModel viewModel)
{
Employee employee = GetEmployee(viewModel.EmployeeId);
TryUpdateModel(employee);
if (ModelState.IsValid)
{
SaveEmployee(employee);
TempData["message"] = "Employee has been saved.";
return RedirectToAction("Details", new { id = employee.EmployeeID });
}
return View(viewModel); // validation error, so redisplay same view
}
It keeps failing, ModelState.IsValid
keeps returning false and redisplaying the view. But I have no idea what the error is.
Is there a way to get the error and redisplay it to the user?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…