Returning a list of keys with ModelState errors

送分小仙女□ 提交于 2019-12-10 14:32:31

问题


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)

回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/888521/returning-a-list-of-keys-with-modelstate-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!