我的控制器中有此功能。
[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
}
它不断失败,ModelState.IsValid
不断返回false并重新显示视图。但是我不知道错误是什么。
有没有办法得到错误并重新显示给用户?