2011-01-20 82 views
0

当在asp.net mvc中显示下拉列表时,我有“全部”选项(全选)。我认为ALL的价值更好的方法是给列表的附加列表计数。但我不能用下面的代码做到这一点:DropDownList ASp.NET MVC ALL选项

myModel.CustomerDropDownList.Last().Value = customers.Count().ToString(); 
View("CustomerView",myModel); 

但它仍然在下拉列表中显示“所有”值。

回答

0

由于我还不能评论,请给我更多的代码示例。您必须在某处放置“全部”文字。所有你正在做的事情,我可以告诉的是使下拉的最后一项是你有多少物品的数量。

<select id='test' name='test'> 
    <option value='a'>Customer 1</option> 
    <option value='b'>Customer 2</option> 
    <option value='3'>Customer 3</option> 
</select> 

这就是我所看到的。

0

CustomerDropDownList是什么类型?

我有一种有趣的感觉,你可能会尝试使用网络表单下拉列表?

道歉,如果不是。

这里是样本名单看起来像我:

var numbers = new[] {1, 2, 3}; 
     IEnumerable<SelectListItem> selectItems = numbers.Select(n => new SelectListItem {Text = n.ToString(), Value = n.ToString(), Selected = true});