views:

727

answers:

3

Hello everybody,

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 of 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!

A: 

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. There are a number of tools that can help you with this, but I prefer the AJAX control toolkit.

NickLarsen
+2  A: 

You're looking for a Cascading Drop Down.

Yuriy Faktorovich
+2  A: 

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.

Baddie