I don't know how to exactly have Cascading DropDownLists
My scenario is the next:
Category has Items and Items have quantities depending on Establishment
I want to have two DropDownLists one which you select a Category, next one is populated when you make a selection of the first with the Items in that Category, and when you select the Item a table with the quantities for each establishment is shown.
Ok this would be my 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();
}
then, I would have my two DropDownLists that should post values to Item_ID and Category_ID ... first category then item
@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" })
This is what I don't know how to do ... how should I put the URL or how should I send it, so when I send the other ID does'nt mix up and I can receive my IDs
How do I receive the values of each DropDownList in the ActionResult? how should they be sent?
ANSWER
I found the answer from this website, just wanted to let know what I did
http://kmsystems.squarespace.com/journal/2009/5/31/aspnet-mvc-cascading-dropdownlists.html