public static MvcHtmlString Alert(this HtmlHelper helper, TempDataDictionary tempDataDictionary) { var viewData = tempDataDictionary.Where(c => c.Key == "success" || c.Key == "warning" || c.Key == "info" || c.Key == "danger"); string alertType = string.Empty; string alertContent = string.Empty; foreach (var item in viewData) { if (item.Value != null) { alertType = item.Key; alertContent = item.Value.ToString(); break; } } if (String.IsNullOrEmpty(alertType) || String.IsNullOrEmpty(alertContent)) { return(null); } string str = $@"<div class='alert alert-{alertType} alert-dismissable'>" + $"{alertContent}" + $"<button type='button' class='close' data-dismiss='alert' aria-hidden='true' class='btn-alert-x'>×</button>" + @"</div>"; return(new MvcHtmlString(str)); }