我不知道如何准确地拥有 Cascading DropDownLists
我的场景是下一个:
类别有项目,项目有数量取决于机构
我想要两个 DropDownLists 一个,您选择一个类别,当您使用该类别中的项目选择第一个时填充下一个,当您选择项目时,将显示一个包含每个机构数量的表格。
好的,这将是我的 ActionResult
public ActionResult ItemByClinic(Guid? Item_ID, Guid? Category_ID)
{
ViewData["Categories"] = InventoryDb.Categories;
if (Category_ID != null)
{
ViewBag.Category_ID = Category_ID;
ViewData["Items"] = InventoryDb.Items.Where(i => i.Category.ID == Category_ID);
if (Item_ID != null)
{
ViewBag.Item_ID = Item_ID;
ViewData["Inventory"] = InventoryDb.Items.Single(i => i.ID == Item_ID).Inventory;
}
}
return View();
}
然后,我将有我的两个 DropDownLists 应该将值发布到 Item_ID 和 Category_ID ...第一个类别,然后是项目
@Html.DropDownList("Categories", new SelectList((IQueryable<Inventario_Data.Models.Category>)ViewData["Categories"], "ID", "Name", ViewBag.Category_ID), "Select an Item Category", new { onchange = "window.location.href = '/Inventory/ItemByClinic/Categody_ID=' + this.value" })
这就是我不知道该怎么做......我应该如何放置 URL 或者我应该如何发送它,所以当我发送另一个 ID 时不会混淆,我可以收到我的 ID
如何接收 ActionResult 中每个 DropDownList 的值?应该如何发送?
回答
我从这个网站上找到了答案,只是想知道我做了什么
http://kmsystems.squarespace.com/journal/2009/5/31/aspnet-mvc-cascading-dropdownlists.html