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

enter image description here

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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -