I have a nested data object for a set of items within categories. Each category can contain sub categories and there is no set limit to the depth of sub categories. (A file
Create your own HtmlHelper extension method like so:
namespace System.Web.Mvc
{
public static class HtmlHelperExtensions
{
public static string CategoryTree(this HtmlHelper html, IEnumerable categories)
{
string htmlOutput = string.Empty;
if (categories.Count() > 0)
{
htmlOutput += "";
foreach (Category category in Categories)
{
htmlOutput += "- ";
htmlOutput += category.Name;
htmlOutput += html.CategoryTree(category.Categories);
htmlOutput += "
";
}
htmlOutput += "
";
}
return htmlOutput;
}
}
}
Funny you should ask because I actually created one of these just yesterday.