How to read modelstate errors when returned by Json?

Posted by learning on Stack Overflow See other posts from Stack Overflow or by learning
Published on 2010-05-11T05:38:46Z Indexed on 2012/08/29 21:39 UTC
Read the original article Hit count: 160

Filed under:

How can I display modelstate errors returned by Json ?

I want to do somthing like that...

 if (!ValidateLogOn(Name, currentPassword))
            {
                ModelState.AddModelError("_FORM", "Username or password is incorrect.");

                 //Return a json object to the javascript
                return Json(new { ModelState });
            }

What must be my code in the view to read the modelstate errors and display them?

My actual code in the view is as follows to read the Json values:

function createCategoryComplete(e) { 
var obj = e.get_object(); 
alert(obj.Values); 

}

© Stack Overflow or respective owner

Related posts about asp.net-mvc