public static object ToJsonValidation(this ModelStateDictionary modelState) { var v = from m in modelState.AsEnumerable() from e in m.Value.Errors select new { m.Key, e.ErrorMessage }; return(new { IsValid = modelState.IsValid, PropertyErrors = v.Where(x => !string.IsNullOrEmpty(x.Key)), ModelErrors = v.Where(x => string.IsNullOrEmpty(x.Key)) }); }
public ValidationSummaryModel(ModelStateDictionary modelState, bool includePropertyErros) { this.IncludePropertyErros = includePropertyErros; if (includePropertyErros) { this.PropertyErrors = modelState.AsEnumerable(); } else { this.PropertyErrors = modelState.Where(p => string.IsNullOrEmpty(p.Key)); } }
public static SimpleModelState ToJsonValidation(this ModelStateDictionary modelState) { var v = from m in modelState.AsEnumerable() from e in m.Value.Errors select new SimpleError { Key = m.Key, ErrorMessage = e.ErrorMessage }; v = v.ToList(); var pe = v.Where(x => !string.IsNullOrEmpty(x.Key)).ToList(); var me = v.Where(x => string.IsNullOrEmpty(x.Key)).ToList(); return(new SimpleModelState { IsValid = modelState.IsValid, PropertyErrors = pe, ModelErrors = me }); }