public static void AddAlert(this TempDataDictionary tempData, string messageClass, string message) { var alerts = tempData.GetAlerts(); alerts.Add(new Alert(messageClass, message)); }
public static MvcHtmlString Summary(TempDataDictionary tempDictionary) { var errors = tempDictionary.GetErrors(); var warnings = tempDictionary.GetWarnings(); var alerts = tempDictionary.GetAlerts(); var anyErrors = errors != null; var anyWarnings = warnings != null; var anyAlerts = alerts != null; if (!anyErrors && !anyWarnings && !anyAlerts) { // exit quickly return null; } var sb = new StringBuilder(); sb.Append("<ul class='messageSummary'>"); if (anyErrors) { foreach (var error in errors) { sb.AppendFormat("<li class='errorMessage'>{0}</li>", error); } } if (anyWarnings) { foreach (var warning in warnings) { sb.AppendFormat("<li class='warningMessage'>{0}</li>", warning); } } if (anyAlerts) { foreach (var alert in alerts) { sb.AppendFormat("<li class='alertMessage'>{0}</li>", alert); } } sb.Append("</ul>"); return MvcHtmlString.Create(sb.ToString()); }
public static void AddAlert(this TempDataDictionary tempData, Alert alert) { var alerts = tempData.GetAlerts(); alerts.Add(alert); }