我不知道如何准确有层叠DropDownListsMVC 3层叠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
我该如何接收每个DropDownList的值在ActionResult中?他们应该如何发送?
ANSWER
我发现从这个网站的答案,只是想让知道我做了什么
http://kmsystems.squarespace.com/journal/2009/5/31/aspnet-mvc-cascading-dropdownlists.html
小心分享一些代码?你可以通过jQuery-Ajax来做到这一点。 –
那么事情是,我不知道从哪里开始......我有两个DropDownLists ..哪一个取决于另一个......我可以通过将它们放置在代码隐藏的ViewData上来获取值,但是在在ActionResult中的代码隐藏我不知道如何检索两个DropDownLists的ID ... – sergioadh
所以你_do_有一些代码。张贴在这里,以便我们可以看到是什么导致你的麻烦。 –