Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of All Countries DropDown

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?

like image 929
Mike Debela Avatar asked Apr 24 '15 11:04

Mike Debela


People also ask

How many countries are list?

There are 195 countries in the world today. This total comprises 193 countries that are member states of the United Nations and 2 countries that are non-member observer states: the Holy See and the State of Palestine.

How can I add country in HTML?

A Country Code is a 2-character code that specifies a country. HTML uses 5-character ISO codes according to this pattern: ll-CC. The ll = lower-case language code, and the CC = upper-case country code.


1 Answers

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

like image 186
3dd Avatar answered Oct 08 '22 23:10

3dd