问:为什么我的ModelState.AddModelError()会出现两次?
控制器:
[HttpPost]
public ActionResult Create(MyObject obj)
{
if (ModelState.IsValid)
{
if (true)
{
ModelState.AddModelError("", "Record already exists.");
return View(obj);
}
db.myOBJs.Add(obj);
db.SaveChanges();
return RedirectToAction("ViewObjs", "Controller");
}
return View(obj);
}
查看:
@Html.ValidationSummary(true, "Action was unsuccessful.")