¿ModelState.AddModelError aparece dos veces?

Q: Why is my ModelState.AddModelError() showing up twice?

enter image description here

Controlador:

    [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);
    }

Vista

@Html.ValidationSummary(true, "Action was unsuccessful.")

preguntado el 08 de noviembre de 11 a las 18:11

have you tried to use actual error id instead of "" -

@EmmanuelN: Actual error? The first parameter is the property that the error is for. And since the error is for the entire model, "" is the correct thing to use. -

@Jacquo: You need to show the entire action and not just the error handling. -

@jgauffin: Thanks for the reply. I have edits specifying full controller code. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.