views:

466

answers:

1

Is there a good way in asp.net MVC to trace ModelState errors? IsValid returns false when I submit my form even if there aren't actually any fields in it, or anything being validated. I looked at this thread here and tried Steve Willcock's suggestion but no exceptions are thrown, just a generic error.

Is there any way I can see what is causing the ModelState to become invalid without stepping through every single part of the model that's used? It's quite large and I was just wondering if there is a more efficient way.

+1  A: 

I had this issue and found that in my model I had a unique id of type int that was causing a problem. When I set it to nullable in my model the error went away.

W/out seeing any of your code though it's a bit hard to figure out but the above helped me.

I also noticed that when I was doing validations, using the Nerd Dinner approach, I would sometimes get an error popup saying something like "Value Required". Linked it to the same problem and made all Id's nullable.

Hope this helps.

griegs
I was able to track down the error and it was in fact exactly what you describe. Get's fairly hard to debug when you have very large entities. I wish there was a more detailed error or exception thrown when this happens.
Graham