根据所选国家/地区填充州下拉列表

时间:2018-12-14 21:09:33

标签: c# asp.net asp.net-mvc

我有这2个下拉列表国家和州。我需要根据所选国家填充或刷新州下拉列表值。没有数据库该怎么办?

助手类:

public class List
{
    public static IEnumerable<SelectListItem> StatesList()
    {
        IList<SelectListItem> states = new List<SelectListItem>
        {
            new SelectListItem() {Text="--Select a state--", Value=""},
            new SelectListItem() {Text="Alabama", Value="AL"},
            new SelectListItem() { Text="Alaska", Value="AK"},
            new SelectListItem() { Text="Arizona", Value="AZ"}

        };

        IList<SelectListItem> states1 = new List<SelectListItem>
        {
            new SelectListItem() {Text="--Select a state--", Value=""},
            new SelectListItem() {Text="Alberta", Value="AB"},
            new SelectListItem() {Text="British Columbia", Value="BC"},
            new SelectListItem() {Text="Manitoba", Value="MB"}

        };
        return states;
    }

    public static IEnumerable<SelectListItem> CountryList()
    {
        IList<SelectListItem> country = new List<SelectListItem>
        {
            new SelectListItem() {Text = "--Select a Country--", Value = ""},
            new SelectListItem() {Text= "Canada", Value = "Can"},
            new SelectListItem() {Text = "Unites States of America", Value = "USA"}
        };
        return country;
    }
}

查看:

 @Html.DropDownListFor(x => x.Country, Myproject.Helpers.List.GetCountryList(), new { @class = "form-control ", placeholder = "--Select a country--" })
 
  @Html.DropDownListFor(x => x.State, Myproject.Helpers.List.GetCountryList(), new { @class = "form-control", placeholder = "--Select a country--" })

0 个答案:

没有答案