c# - Populating Dropdown using Reflection -


i using mvc4 , want use dropdown connected search box search selected property. how stuck on text= prop.name. how go through , access of properties using this.

my controller

public actionresult searchindex(string searchstring)     {         var selectlistitems = new list<selectlistitem>();          var first = db.bloodstored.first();         foreach(var item in first.gettype().getproperties())         {             selectlistitems.add(new selectlistitem(){ text = item.name, value = selectlistitems.count.tostring()});         }         ienumerable<selectlistitem> enumselectlist = selectlistitems;         viewbag.searchfields = enumselectlist;           var bloodsearch = m in db.bloodstored                           select m;          if (!string.isnullorempty(searchstring))         {             bloodsearch = bloodsearch.where(s => string.compare(getvalue(s, propertyname), searchstring) == 0);         }         return view(bloodsearch);     } 

the selectlist working need go on searchstring , how pass 2 parameters now.

i'm not quite sure you're asking. if want create list of objects property text set property name of object, first object in bloodstored enumerable , create list of anonymous types:

// 1 instance , iterate properties var selectlistitems = new list<object>(); var first = db.bloodstore.first(); foreach(var item in first.gettype().getproperties()){     selectlistitems.add(new (){ text = item.name}); }  viewbag.searchfields = selectlistitems; 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -