Domanda

Come posso restituire un elenco / array di tutte le chiavi che hanno un errore?

Ho cercato di fare il seguito, ma dice che non posso avere quel tipo di espressione per qualche motivo.

ModelState.ToList(item => item.Value.Errors.Count > 0)
È stato utile?

Soluzione

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

Altri suggerimenti

Conte è un metodo. Avete bisogno di () s dopo è. Ma preferirei Qualsiasi, in ogni caso:

from item in ModelState
where item.Value.Errors.Any()
select item.Key
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top