tags:

views:

181

answers:

2

I would like to return a list/array of all keys that have an error against them. I have tried to do ModelState.ToList(item => item.Value.Errors.Count>0) but it says I can't have that sort of expression for some reason.

Thanks

+1  A: 

Count is a method. You need ()s after is. But I'd prefer Any, anyway:

from item in ModelState
where item.Value.Errors.Any()
select item.Key
Craig Stuntz
No overload for method 'ToList' takes '1' arguments
Jon
I also just want the keys collection returned not the KeyValuePair collection
Jon
I rewrote your code as LINQ. This is from memory, so I don't guarantee no errors or typos.
Craig Stuntz
A: 
var errors = from modelstate in ModelState.AsQueryable().Where(f => f.Value.Errors.Count > 0) select new  {  Title = modelstate.Key  };
Jon