public static IEnumerable Errors(this System.Web.Http.ModelBinding.ModelStateDictionary modelState) { if (!modelState.IsValid) { return(modelState.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Errors .Select(e => e.ErrorMessage).ToArray()) .Where(m => m.Value.Any())); } return(null); }