public static MvcHtmlString WriteModels(this HtmlHelper htmlHelper, Templates templates) { if (templates == null || templates.Models == null || !templates.Models.Any()) return MvcHtmlString.Empty; var stringBuilder = new StringBuilder("<script type=\"text/javascript\" language=\"javascript\">\n"); foreach (var model in templates.Models) { stringBuilder.AppendFormat("var {0} = {1};\n", model.Key, Json.Encode(model.Value)); } stringBuilder.Append("</script>\n"); return MvcHtmlString.Create(stringBuilder.ToString()); }
public static MvcHtmlString RenderTemplates(this HtmlHelper htmlHelper, Templates templates) { if (templates == null || templates.Render == null || !templates.Render.Any()) return MvcHtmlString.Empty; var stringBuilder = new StringBuilder("<script type=\"text/javascript\" language=\"javascript\">\n"); foreach (var template in templates.Render) { stringBuilder.AppendFormat("var html = ich.{0}({1});\n", template.Name, template.Model); stringBuilder.AppendFormat("$(\"{0}\").html(html);\n", template.Selector); } stringBuilder.Append("</script>\n"); return MvcHtmlString.Create(stringBuilder.ToString()); }