MVC3 Dropdown drillthrough hierarchy
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.
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.
What is the best way to do this? I am considering jQuery and JSON, but there might be a better way.
I have the following GetCategoryChildren method:
public string ThisName { get; set; }
public int ThisHLevel { get; set; }
public IEnumerable<SelectListItem> Children { get; set; }
public GetCategoryChildren(int category_ID)
{
var rep = new Product_CategoryRepository();
Children = rep.All.Where(x => x.Parent_id == category_ID).ToList()
.Select(x =>开发者_如何学编程 new SelectListItem
{
Text = x.Name,
Value = x.Category_ID.ToString()
});
ThisName = rep.All.Where(x => x.Category_ID == category_ID)
.FirstOrDefault().Name;
ThisHLevel = rep.All.Where(x => x.Category_ID == category_ID)
.FirstOrDefault().HLevel;
}
Lend me your brains.
Take a look at Project Awesome
The AjaxDropdown does the trick.
精彩评论