Tutorial :Returning a list of keys with ModelState errors


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)  


var errors = from modelstate in ModelState.AsQueryable().Where(f => f.Value.Errors.Count > 0) select new  {  Title = modelstate.Key  };  


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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »