I met this requirement by adding an attribute to the parameters and the value of the attribute will be the name Optgroup that I want to have. And on the client side, I used this code to render a drop-down list using optgroups var optGroup = "";
var i = 0; $(this).find("option").each(function () { if (optGroup !== "") optGroup += "," + $(this).attr("OptGroup"); else optGroup = $(this).attr("OptGroup"); }); var optGroups = $.unique(optGroup.split(",")); for (var optGroupEle in optGroups) { if ($("optgroup[label='" + optGroups[optGroupEle] + "']").html() == null) $("option[OptGroup='" + optGroups[optGroupEle] + "']").wrapAll("<optgroup label='" + optGroups[optGroupEle] + "'/>"); }
source share