0

我有我需要绑定到 mvc 中的下拉列表的字典列表。

public static readonly Dictionary<string, string> lstGender = new Dictionary<string, string>() { { "M", "Male" }, { "F", "Female" } };

如何将 lstGender 绑定到 mvc 中的下拉列表。

提前致谢

4

1 回答 1

0

这样做..

 Dictionary<Int32, string> dict = new Dictionary<int, string>();
            dict.Add(0, "All");
            dict.Add(1, "Male");
            dict.Add(2, "Female");
            dict.Add(3, "Snr Citizen");
            dict.Add(4, "Children");


            ViewBag.Buckets = dict.Select(item => new SelectListItem() { Value = item.Key.ToString(), Text = item.Value });

在视图中绑定这样

@Html.DropDownList("ddlbucket", (IEnumerable)ViewBag.Buckets)

于 2014-01-30T10:50:17.797 回答