问题
I used this code to populate my dropdownlist with countries list:
public JsonResult GetAllCountries()
{
var objDict = new Dictionary<string, string>();
foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
var regionInfo = new RegionInfo(cultureInfo.Name);
if (!objDict.ContainsKey(regionInfo.EnglishName))
{
objDict.Add(cultureInfo.EnglishName, regionInfo.TwoLetterISORegionName.ToLower());
}
}
var obj = objDict.OrderBy(p => p.Key).ToArray();
return Json(obj.Select(t => new
{
Text = t.Key,
Value = t.Value
}), JsonRequestBehavior.AllowGet);
}
It populates This Way. And I used same code but Console, and shows differently Here. Why? And what should I do to populate the dropdownlist like the second one?
回答1:
The line
objDic.Add(cultureInfo.EnglishName, regionInfo.TwoLetterISORegionName.ToLower());
Should read
objDic.Add(regionInfo.EnglishName, regionInfo.TwoLetterISORegionName.ToLower());
This will have the website output the same as the console app
来源:https://stackoverflow.com/questions/29845769/list-of-all-countries-dropdown