asp.net mvc 5 - Dropdown menu from SELECT distinct -
i trying create drop-down menu distinct values.
select distinct rolegroup ccf.role
in controller am
var rolegroups = db.roles.select(x => x.rolegroup).distinct(); viewbag.rolegroups = new selectlist(rolegroups, "rolegroup", "rolegroup", null);
in view am
@html.dropdownlistfor(model => model.rolegroup, (@viewbag.rolegroups) ienumerable<selectlistitem>, new { htmlattributes = new { @class = "form-control" } })
i error of
what this?
your query returning ienumerable<string>
, selectlist
constructor trying access rolegroup
property of string
(the 2nd , 3rd parameters) not exist. needs be
viewbag.rolegroups = new selectlist(rolegroups);
Comments
Post a Comment