码迷,mamicode.com
首页 > 其他好文 > 详细

modelstate.isvalid false

时间:2016-06-30 14:24:20      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/1791570/modelstate-isvalid-false-why

第一个

About "can it be that 0 errors and IsValid == false": here‘s MVC source code fromhttp://aspnet.codeplex.com/sourcecontrol/changeset/view/23011?projectName=aspnet#266501

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.

 

 

第二个

As you are probably programming in Visual studio you‘d better take advantage of the possibility of using breakpoints for such easy debugging steps (getting an idea what the problem is as in your case).

Just place them just in front / at the place where you check ModelState.isValid and hover over the ModelState.

Now you can easily browse through all the values inside and see what error causes the isvalid return false.

可以直接用lambda表达式把错误筛选出来ModelState.Values.Select(x=>x.Errors).Where(x=>x.Count>0)

技术分享

 

modelstate.isvalid false

标签:

原文地址:http://www.cnblogs.com/chucklu/p/5629696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!