在操作删除的情况下,如何将模型状态错误从一个操作传递到另一个操作?
public ActionResult Index()
{
ProjectTestModel model = new ProjectTestModel ();
return GetProjectView(model);
}
public ActionResult GetProjectView(ProjectTestModel model)
{
return View("Index", model);
}
public ActionResult Delete(int id)
{
try
{
test.Load(id)
test.Delete();
return RedirectToAction("Index");
}
catch (Exception e)
{
ModelState.AddModelError("Error", e.Message);
return RedirectToAction("Index");
}
}
最佳答案
您可以考虑使用TempData传递错误消息。
关于asp.net - 如何将错误从一个操作传递到另一个操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5075323/