Let say we have a class
Category { ID, Name, ParentID }
and a List
1, \'Item 1\', 0 2, \'Item 2\', 0 3, \'Item 3\'
@model List @{ Func, string> recuresive = null; recuresive = (parentid, list) => string.Join("", list.Where(x => x.ParentId == parentid).Select(x => "" + x.Name + "" + recuresive(x.Id, list.Where(y => y.ParentId != parentid).ToList()) + "")); } @Html.Raw("" + recuresive(null, Model) + "")