public static void WriteAjaxException(this HttpResponseBase response, Exception ex) { var vex = ex as DbEntityValidationException; if (vex != null) { var msg = new StringBuilder(); foreach (var validationError in vex.EntityValidationErrors) { foreach (var error in validationError.ValidationErrors) { msg.AppendLine(string.Format("{0}: {1}", error.PropertyName, error.ErrorMessage)); } } response.WriteAjax(new { success = false, msg = msg.ToString() }, true, 400); return; } var sb = new StringBuilder(); var exc = ex; do { sb.AppendLine(string.Format("[{0}]: {1}\r\n", exc.GetType(), exc.Message)); if (exc.InnerException != null) { exc = exc.InnerException; } else { break; } } while (true); response.WriteAjax(new { success = false, msg = sb.ToString() }, true, 500); }
public void WriteToResponse() { _response.WriteAjax(this); }