所有国家/地区列表下拉列表 [英] List of All Countries DropDown

查看:104
本文介绍了所有国家/地区列表下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在国家列表中填充了我的下拉列表:

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);
}

它填充这种方式.而且我使用了与Console相同的代码,并在此处显示了不同的内容.为什么?我应该怎么做才能像第二个一样填充下拉列表?

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?

推荐答案

objDic.Add(cultureInfo.EnglishName,regionInfo.TwoLetterISORegionName.ToLower());

应阅读

objDic.Add(regionInfo.EnglishName,regionInfo.TwoLetterISORegionName.ToLower());

这将使网站输出的内容与控制台应用程序相同

This will have the website output the same as the console app

这篇关于所有国家/地区列表下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆