ModelState.AddModelError出现两次?

时间:2011-11-08 18:35:52

标签: asp.net-mvc-3

问:为什么我的ModelState.AddModelError()会出现两次?

enter image description here

控制器:

    [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.")

0 个答案:

没有答案