/// <summary> /// This uses the view context to get around the dynamic type and lambda issue in views /// </summary> /// <param name="context"></param> /// <param name="doRender"></param> /// <returns></returns> public static MvcHtmlString RenderScripts(ControllerBase controller, Func <Growl, string> scriptFactory, bool includeScriptTags = true) { GrowlCollection collection = new GrowlCollection(controller); if (scriptFactory != null) { if (collection.Count > 0) { StringBuilder builder = new StringBuilder(); if (includeScriptTags) { builder.AppendLine("<script type=\"text/javascript\">"); } // render out the scripts builder.Append(string.Join(Environment.NewLine, collection.Select(scriptFactory))); // reset collection.Clear(); if (includeScriptTags) { builder.AppendLine("</script>"); } return(MvcHtmlString.Create(builder.ToString())); } } return(null); }
public Growl(ControllerBase controller, string message, string type) { Message = message; Type = type; _collection = new GrowlCollection(controller); }