ASP.NET MVC Canada dropdown list
2 answers
public class CanadianProvinces
{
public static readonly IDictionary<string, string> ProvinceDictionary = new Dictionary<string, string>
{
{"ALBERTA", "AB"},
{"BRITISH COLUMBIA", "BC"},
{"MANITOBA", "MB"},
{"NEW BRUNSWICK", "NB"},
{"NEWFOUNDLAND AND LABRADOR", "NL"},
{"NORTHWEST TERRITORIES", "NT"},
{"NOVA SCOTIA", "NS"},
{"NUNAVUT", "NU"},
{"ONTARIO", "ON"},
{"PRINCE EDWARD ISLAND", "PE"},
{"QUEBEC", "QC"},
{"SASKATCHEWAN", "SK"},
{"YUKON", "YT"},
};
public static SelectList ProvinceSelectList
{
get { return new SelectList(ProvinceDictionary, "Value", "Key"); }
}
}
And then it is used like this:
<%= Html.DropDownList("province", CanadianProvinces.ProvinceSelectList)%>
+7
source to share
Mixed case in case anyone needs it (edit if there are typos):
public class CanadianProvinces
{
public static readonly IDictionary<string, string> ProvinceDictionary =
new Dictionary<string, string>
{
{"Alberta", "AB"},
{"British Columbia", "BC"},
{"Manitoba", "MB"},
{"New Brunswick", "NB"},
{"Newfoundland and Labrador", "NL"},
{"Northwest Territories", "NT"},
{"Nova Scotia", "NS"},
{"Nunavut", "NU"},
{"Ontario", "ON"},
{"Prince Edward Island", "PE"},
{"Quebec", "QC"},
{"Saskatchewan", "SK"},
{"Yukon", "YT"}
};
public static SelectList ProvinceSelectList
{
get { return new SelectList(ProvinceDictionary, "Value", "Key"); }
}
}
+3
source to share