title: MVC3 Dropdown drillthrough hierarchy
body: <p>I have a table for product category that has a hierarchical structure. Each Category_ID may have a number of children determined by their Parent_id. For example Air Fresheners (26) has children 26, 27 and 28 as they have a Parent_id of 25. </p>
  
  <p><img src="https://i.stack.imgur.com/5zO3Y.png" alt="Category table"></p>
  
  <p>I would like to set up a page to drill through the categories with dropdowns. A user would select a level 2 category such as Air Fresheners they would then get a dropdown containing children of the previous selection.</p>
  
  <p>What is the best way to do this? I am considering jQuery and JSON, but there might be a better way. </p>
  
  <p>I have the following GetCategoryChildren method:</p>
  
  <pre><code>public string ThisName { get; set; }
  public int ThisHLevel { get; set; }
  public IEnumerable&lt;SelectListItem&gt; Children { get; set; }
  
  public GetCategoryChildren(int category_ID)
  {
      var rep = new Product_CategoryRepository();
      Children = rep.All.Where(x =&gt; x.Parent_id == category_ID).ToList()
                        .Select(x =&gt; new SelectListItem
              {
                  Text = x.Name,
                  Value = x.Category_ID.ToString()
              });
      ThisName = rep.All.Where(x =&gt; x.Category_ID == category_ID)
                        .FirstOrDefault().Name;
      ThisHLevel = rep.All.Where(x =&gt; x.Category_ID == category_ID)
                          .FirstOrDefault().HLevel;
  }
  </code></pre>
  
  <p>Lend me your brains.</p>