Returning a list of keys with ModelState errors

Jon picture Jon · May 20, 2009 · Viewed 7.1k times · Source

How can I return a list/array of all keys that have an error?

I have tried to do the below, but it says I can't have that sort of expression for some reason.

ModelState.ToList(item => item.Value.Errors.Count > 0)

Answer

Jon picture Jon · May 22, 2009
var errors = from modelstate in ModelState.AsQueryable().Where(f => f.Value.Errors.Count > 0) select new  {  Title = modelstate.Key  };