razor Html.DropdownList provide “Please select” as optionLabel AND “US” as selectedValue

后端 未结 4 1817
情话喂你
情话喂你 2021-02-01 10:21

Data:

var countries = new Dictionary();
countries.Add(\"AF\",\"Afghanistan\");
countries.Add(\"US\",\"United States\");
cou         


        
4条回答
  •  萌比男神i
    2021-02-01 11:13

    I know this post is old, but for people looking for list of coutries this is the easy way :

    // List of coutries
    List CountryList = new List();
    
    CultureInfo[] CInfoList = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
    
    CountryList.Add("");
    foreach (CultureInfo CInfo in CInfoList)
    {
        RegionInfo R = new RegionInfo(CInfo.LCID);
        if (!(CountryList.Contains(R.EnglishName)))
        {
            CountryList.Add(R.EnglishName);
        }
    }
    CountryList.Sort();
    

提交回复
热议问题