How do I figure out which of the keys in ModelState that contains an error when ModelState.IsValid is false? Usually I would just hover the mouse thru the ModelState.Values list checking item by item for error count > 0. But now I'm working on a view that has some lists of complex objects, totalling 252 ModelState items(each item of each object of each list has an entry on ModelState.Keys).
So, is there an easier way to point out the error source?
Best Answer
You can check the
ViewData.ModelState.Values
collection and see what are the Errors.If you really want the Keys(the property name), You can iterate through the
ModelState.Keys