简体   繁体   中英

asp.net mvc - cascading dropdown - one single table

I need to approach a cascading dropdownlist in asp.net mvc using one single table. I downloaded maxmind.com worldcities where the database scheme displays the following fields:

  • Country Code
  • ASCII City Name
  • City Name
  • State/Region
  • Population
  • Latitude
  • Longitude

I would like to know what do I have to develop in order to create a cascading dropdown where in the first dropdown displays country data and in the second one displays State data associated to the selected country.

Example or tutorial link will be highly appreciated. brgds!

You have to use some grouping...

you could use following

dim query = from i in mydata group by i.country into regions = Group select country, regions

This gives you the basic. Is linq, if you know what i mean.

No you assign the frist dropdown with the query and use just the "country" keyword. After a user selects a country, use ajax or the usual postback to request an update for the second dropdown. there you will do following

query is still the object holding your grouped query by country...

so...

dim states = (from i in query where i.country = "myselectedCountry" select i.regions).single()

now you have all the regions in one query, you can now bind it to a dropdown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM