c# - ASP.net MVC Grouping within a SelectList -
i want create grouped select list, e.g. similar travel sites:
- europe - london - paris - madrid - north america - new york - toronto - asia - hong kong - bangkok
my model looks this:
public class topic { public virtual guid id { get; private set; } public virtual string code { get; set; } public virtual string description { get; set; } public virtual string groupdescription { get; set; } }
where code value select, description text want show, , groupdescription want group by.
i found groupby method on selectlist - i'm not sure how use achieve end (if indeed correct method use!)
i create selectlist in controller this:
private ienumerable<selectlistitem> generatetopiclist() { var selectoptions = concern in _topicsrepository.listtopics() select new selectlistitem { value = concern.code, text = concern.groupdescription + " : " + concern.description, }; return new selectlist(selectoptions, "value", "text"); }
and use in view this:
<%= html.dropdownlist("concerns[0].topic", (selectlist)viewdata["topics"])%>
the problem drop down wide both description , group description on same line.
is possible group selectlist topics want do?
i'm using mvc 3.
cheers!
Comments
Post a Comment