ModelState.IsValid == false,为什么? [英] ModelState.IsValid == false, why?

查看:52
本文介绍了ModelState.IsValid == false,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到导致 ModelState 无效的错误列表?我没有在 ModelState 对象上看到任何错误属性.

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.

推荐答案

关于can it be that 0 errors and IsValid == false":这里是 https://github.com/Microsoft/referencesource/blob/master/System.Web/ModelBinding/ModelStateDictionary.cs#L37-L41

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

现在看来不可能了.嗯,这适用于 ASP.NET MVC v1.

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

这篇关于ModelState.IsValid == false,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆