Hunting for errors ModelState.IsValid

Is there a good way in asp.net MVC to track ModelState errors? IsValid returns false when I submit my form, even if it does not have any fields or anything validated. I looked at this thread here and tried Steve Willcock's suggestion, but there were no exceptions, just a common mistake.

Is there any way to see what causes the ModelState to become invalid without going through each part of the model used? It's quite large, and I'm just wondering if there is a more efficient way.

+4
source share
1 answer

I had this problem and I found that in my model I had a unique identifier of type int which caused the problem. When I set it to NULL in my model, the error disappeared.

I also noticed that when I did the checks using the Nerd Dinner approach, sometimes I got an error popup saying something like “Required value”. Associated it with the same problem and made all identifiers null.

Hope this helps.

+2
source

All Articles