Reputation: 36743
Imagine a drop down list of States:
Florida
Washington
Maryland
Maine
According to the chosen state, I need to load a collection of Cities within that state.
My database schema is already created for this situation:
State City
--------- -----------
ID ID
Name Name
StateID
I'm thinking about using ajax to fetch JSON response from an ActionMethod and use jQuery to load those values into the city drop down list.
Is this a good path to follow?
Since I need to get the selected city ID (in order to process what city the request came from), how do I assign not only the text, but also the ID to the drop down list item?
Any suggestions on how to approach this?
Upvotes: 0
Views: 215
Reputation: 4770
This is a common question and is referred to as a 'cascading dropdown list'
Try googling
'asp.net mvc jquery ajax cascading dropdownlist'
and you should find plenty of info, tutorials etc
Upvotes: 1