title: ASP.NET MVC Repeater Help
body: <p>I have built a little repeater HtmlHelper for asp.net MVC and I would like to be able to recurse through to build an tree style list. So if <code>&lt;T&gt;</code> has any children that are <code>IEnumerable</code> I would like to add them as embedded lists.</p>
  
  <p>Here is what I have so for which creates a flat list...</p>
  
  <pre><code>    public static MvcHtmlString Repeater&lt;T&gt;(this HtmlHelper html, IEnumerable&lt;T&gt; items,
          Func&lt;T, HelperResult&gt; itemTemplate,            
          Func&lt;string, HelperResult&gt; containerTemplate,
          Func&lt;string, HelperResult&gt; emptyTemplate)
      {
          if (items == null)
              return MvcHtmlString.Create(HttpContext.Current.Server.HtmlDecode(emptyTemplate("No Results").ToHtmlString()));
  
          if (items.Count() == 0)
              return MvcHtmlString.Create(HttpContext.Current.Server.HtmlDecode(emptyTemplate("No Results").ToHtmlString()));
  
          StringBuilder sb = new StringBuilder();
  
          foreach (var item in items)
          {
              string content = itemTemplate(item).ToHtmlString();
  
              //Here I would want to append the children to 'content' using containerTemplate and itemTemplate....
  
              sb.Append(HttpContext.Current.Server.HtmlDecode(content));
          }
  
          return MvcHtmlString.Create(HttpContext.Current.Server.HtmlDecode(containerTemplate(sb.ToString()).ToHtmlString()));
      }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Cheers in advance.</p>
  
  <p>Gifster</p>