Search code examples
c#asp.nettreerenderingnested-sets

Rendering Nested Comments


I typically render comments in a simple repeater.

I have a social app which requires nested comments (being able to comment on a comment).

So I have objects which look like this:

class Comment
{
    public string Body { get; set; }
    public User Creator { get; set; }
    public List<Comment> ChildComments { get; set; }
}

Can I use nested repeaters? Is that even a good idea? Do I need to pre-render the HTML in a recursive loop and send it to a literal?

Not sure what to do with this one.


Solution

  • You could use an HTML source block, then iterate through the comments, adding a <DIV> for each comment begin, then after each comment, call the iterator on the nest list for that comment, then add the closing </DIV>