支持optgroup in dropdownlist .NET MVC? [英] Support for optgroup in dropdownlist .NET MVC?
问题描述
继续从这个问题以编程方式创建一个下拉列表我希望我的列表也有几个 optgroup
列表。这是否可能?
我知道我需要将一个selectList传递给一个dropDownList,但不知道如何添加文本,值,optgroup到selectList。 >
我想要最终结果产生:
< option value = >请选择< / option>
< optgroup label =选项A>
< option value =1> 1< / option>
< option value =2> 2< / option>
< option value =3> 3< / option>
< option value =4> 4< / option>
< / optgroup>
< optgroup label =选项B>
< option value =a> A< / option>
< option value =b> B< / option>
< option value =c> C< / option>
< / optgroup>
< / option>
查看 www.codeplex.com/aspnet ,并不表示SelectList和DropDownList扩展方法都不支持在一个选择。看起来您需要编写自己的扩展方法,并扩展SelectListItem以包含分组,或者在标记中手动生成选择。
Continuing on from this question programmatically creating a drop down list I would like my list to have several optgroup
lists too. Is this currently possible?
I know I need to pass a selectList to a dropDownList but do not know how to add text, value, optgroup to the selectList.
I want the end result to produce:
<option value="">Please select</option>
<optgroup label="Option A">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</optgroup>
<optgroup label="Option B">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</optgroup>
</option>
Looking through the code on www.codeplex.com/aspnet, it doesn't appear that neither the SelectList nor the DropDownList extension method supports the use of OptGroup in a select. Looks like you'll need to write your own extension method and extend SelectListItem to contain the grouping or generate the select manually in markup.
这篇关于支持optgroup in dropdownlist .NET MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!