title: How group list elements by parent ID like tree in c# MVC4 application?
body: <p>I have Comment model like this:</p>
  
  <pre><code>public class Comment
      {
          public int? ParentId { get; set; }
          public string Text { get; set; }
          public int ProjectId { get; set; }
          public int UserWhoTypeId { get; set; }
      }
  </code></pre>
  
  <p>I want to show comments <strong>one under another by parentID</strong> . Parent Comments will seems in <code>div</code>, child Comments will seems in  </p>
  
  <pre><code>&lt;ul&gt;
     &lt;li&gt;
        child comments go here
     &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>For example, </p>
  
  <pre><code>  &lt;ul&gt;
         &lt;li&gt;
            &lt;div&gt;
                 parent comments go here
            &lt;/div&gt;
            &lt;ul&gt;
               &lt;li&gt;
                   child comments go here
               &lt;/li&gt;
             &lt;/ul&gt;
         &lt;/li&gt;
    &lt;/ul&gt;
  </code></pre>
  
  <p>I firstly need to collect Comments with LINQ <strong>like tree</strong> and then apply it like shown above in view. Any links or advice please.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I created model as</p>
  
  <pre><code>public class CommentListModel
  {
      public Comment Comment{ get; set; }
      public List&lt;Comment&gt; Childs { get; set; }
  }
  </code></pre>
  
  <p>And I collected all comments in 1 list:</p>
  
  <pre><code>List&lt;CommentListModel&gt;  CommentHierarchy = MyService.GetCommentHierarchy();
  </code></pre>
  
  <p><strong>Now, I need to show  CommentHierarchy  in view like tree hierarchy. Please help.</strong></p>