Rebel.Cms.Web.ModelStateExtensions.ToJsonErrors C# (CSharp) Method

ToJsonErrors() public static method

Serializes the ModelState to JSON for JavaScript to interrogate the errors
public static ToJsonErrors ( this state ) : System.Web.Mvc.JsonResult
state this
return System.Web.Mvc.JsonResult
        public static JsonResult ToJsonErrors(this ModelStateDictionary state)
        {
            return new JsonResult
                       {
                           Data = new
                                      {
                                          success = state.IsValid.ToString().ToLower(),
                                          failureType = "ValidationError",
                                          validationErrors = from e in state
                                                             where e.Value.Errors.Count > 0
                                                             select new
                                                                        {
                                                                            name = e.Key,
                                                                            errors = e.Value.Errors.Select(x => x.ErrorMessage)
                                                                 .Concat(
                                                                     e.Value.Errors.Where(x => x.Exception != null).Select(x => x.Exception.Message))
                                                                        }
                                      }
                       };
        }