首页 > 其他 > 详细

modelstate.isvalid false

时间:2016-06-30 14:23:05      阅读:308      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!