Пример #1
0
 public ApiResult(ModelStateDictionary modelState)
     : this()
 {
     if (modelState.Any(m => m.Value.Errors.Count > 0))
     {
         StatusCode  = 400;
         Message     = "The model submitted was invalid. Please correct the specified errors and try again.";
         ModelErrors = modelState.SelectMany(m => m.Value.Errors.Select(me => new ModelError {
             FieldName = m.Key, ErrorMessage = me.ErrorMessage
         }));
     }
 }
 public static IEnumerable <string> GetErrorsFromModelState(this System.Web.Mvc.ModelStateDictionary ModelState)
 {
     return(ModelState.SelectMany(x => x.Value.Errors.Select(error => error.ErrorMessage)));
 }