标签:
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)
标签:
原文地址:http://www.cnblogs.com/chucklu/p/5629696.html