Пример #1
0
        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());
        }