Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC 3: optgroup support in Html.DropDownListFor

How can i make my DropDownListFor support optgroup? Is there anyway to do it? Notice that this is DropDownListFor, means that it support DataAnnotation client validation

like image 889
Hieu Nguyen Trung Avatar asked Jul 14 '11 05:07

Hieu Nguyen Trung


1 Answers

Support for optgroups was added to ASP.Net MVC at version 5.2.

The Group property on SelectListItem allows you to specify a group for each item:

New SelectList constructors also allow you to provide the name of the field that contains the group title on the supplied list of items.

The HtmlHelper DropDownList and DropDownListFor methods now generate optgroup elements based on the groups included on the list of items.

like image 180
Dan Malcolm Avatar answered Sep 28 '22 05:09

Dan Malcolm