这种方法看起来很愚蠢,有点沉重;有没有创造同样的事情(它的MVC视图下拉列表)在C#中创建月份下拉列表ASP.NET MVC
private List<KeyValuePair<int, string>> getMonthListDD
{
get
{
var dDur = new List<KeyValuePair<int, string>>();
dDur.Add(new KeyValuePair<int, string>(1, "January"));
dDur.Add(new KeyValuePair<int, string>(2, "Febuary"));
dDur.Add(new KeyValuePair<int, string>(3, "March"));
dDur.Add(new KeyValuePair<int, string>(4, "April"));
dDur.Add(new KeyValuePair<int, string>(5, "May"));
dDur.Add(new KeyValuePair<int, string>(6, "June"));
dDur.Add(new KeyValuePair<int, string>(7, "July"));
dDur.Add(new KeyValuePair<int, string>(8, "August"));
dDur.Add(new KeyValuePair<int, string>(9, "September"));
dDur.Add(new KeyValuePair<int, string>(10, "October"));
dDur.Add(new KeyValuePair<int, string>(11, "November"));
dDur.Add(new KeyValuePair<int, string>(12, "December"));
return dDur;
}
}
哇这么多的方法对皮肤同兔;但我最喜欢这个,因为它感觉干净。我可能会将它们全部推入大容量并查看哪些是最快的:op – 2010-05-26 10:00:26
这种写法的唯一缺点是MonthNames(1月 - > 12月加上“空白”月份)有13个月的条目。这可能对您的UI有空白框是可以的,但如果您想要自定义选择器标签,那么您需要通过修剪它来解决这个问题。 – Paul 2010-06-27 22:40:35
如果你想做@Paul提到的,你可以简单地在Select语句 – snumpy 2011-05-24 19:39:20