title: Build and render infinite hierarchical category tree from self-referential category table
body: <p>I have a <code>Categories</code> table in which each category has a <code>ParentId</code> that can refer to any other category's <code>CategoryId</code> that I want to display as multi-level HTML list, like so:</p>
  
  <pre><code>&lt;ul class="tree"&gt;
      &lt;li&gt;Parent Category
          &lt;ul&gt;
              &lt;li&gt;1st Child Category
                  &lt;!-- more sub-categories --&gt;
              &lt;/li&gt;
              &lt;li&gt;2nd Child Category
                  &lt;!-- more sub-categories --&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Presently I am recursively rendering a partial view and passing down the next category. It works great, but it's wrong because I'm executing queries in a view.</p>
  
  <p>How can I render the list into a tree object and cache it for quick display every time I need a list of all hierarchical categories?</p>