Populating DropDownList based on another DropDownList (Cascading Drop Down)
I am having trouble getting the functionality we want in our Create View
in our ASP.NET MVC application.
We have got two DropDownLists in our Create
View.
One is a selection of categories and the second should be populated with items based on the id
value o开发者_如何转开发f the first category selected. (They have a FK relationship).
Have you guys encountered any similar situation and can you give me some advice or a hint on how I can tackle this problem best?
- Should I create some specified ActionResult method for this?
- Or should I go with a
static
method in the Repository / Controller?
All help is more than appreciated!
You're looking for a Cascading Drop Down.
Just to clarify what NicklLarsen
said
If you want them to update on the page without having to reload after every selection of the first drop down list, you will want to use cascading drop downs
Cascading drop downs is short for making an AJAX call to another action method with the selected value of the first drop down list. The action method would take that value, use it to look up the corresponding information based on that value, and return a JSON/XML format of the list of items. Using javascript, you would then update the second drop down list with items.
精彩评论