asp.net mvc 3 - MVC 3 Razor: Country selection drop down list

こ雲淡風輕ζ 提交于 2019-12-03 21:12:17

Is this what you want?

ViewBag.country = from p in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures).OrderBy(c=>c.Name)
                          select new SelectListItem
                          {
                              Text = p.EnglishName,
                              Value = p.DisplayName
                          };

Windows and/or .Net do not contain a list of all countries.

The list of languages/cultures is stable, countries come and go, or change name frequently.

Go to the ISO site, and you can download a list of countries from their site. You have to download this list, and update your data frequently.

Update: The list of country codes is no longer freely distributed by ISO, more information can be found on the iso.org site.

And you have to decide, if you want to include countries like Palestine on this list (Palestine is on this list, just an example of "new" countries). You would probably have to add them manually.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!