Recursive mantığını kurmalısın.
public static class HtmlHelperExtensions
{
public static string CatTree(this HtmlHelper html, IEnumerable<Category> cats)
{
string htmlOutput = string.Empty;
if (cats.Count() > 0)
{
htmlOutput += "<ul>";
foreach (Category cat in cats)
{
htmlOutput += "<li>";
htmlOutput += cat.Name;
htmlOutput += html.CatTree(cat.Categories);
htmlOutput += "</li>";
}
htmlOutput += "</ul>";
}
return htmlOutput;
}
}