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
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.