Search code examples
c#asp.net-mvcmodelstate

ModelState.IsValid == false, why?


Where can I find the list of errors of which make the ModelState invalid? I didn't see any errors property on the ModelState object.


Solution

  • About "can it be that 0 errors and IsValid == false": here's MVC source code from https://github.com/Microsoft/referencesource/blob/master/System.Web/ModelBinding/ModelStateDictionary.cs#L37-L41

    public bool IsValid {
        get {
            return Values.All(modelState => modelState.Errors.Count == 0);
        }
    }
    

    Now, it looks like it can't be. Well, that's for ASP.NET MVC v1.