Click here to Skip to main content
15,891,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an IEnumerable<model> model bound to my view and the model contains all plain values. There is no IEnumerable<> value in the model. I need to populate some DropDownList or DropDownListFor with the values from this model. Is there a way that I could populate DropDownList with model property without working in my action method. Here is my model:

@model IEnumerable<kesp.tbl_monitoring>
and my action method is returning value as:

return View(db.tbl_Monitoring.ToList());
Can any one help me, I am stuck and searching from hours, but could not found any solution

What I have tried:

Tried too many options but did not worked for me
Posted
Updated 3-Apr-17 23:32pm
Comments
Karthik_Mahalingam 4-Apr-17 1:54am    
which value you want to populate?
a property of each item in the collection?
Asif_Aziz 4-Apr-17 2:14am    
I want to populate four DropdownList in order to filtering data on my view. like all states in my table so that I can filter record of specific state
Karthik_Mahalingam 4-Apr-17 2:23am    
is the states information available in the model ?
Asif_Aziz 4-Apr-17 2:29am    
yes
tbl_Monitoring.state but I am unable to produce an dropdownList on it
Karthik_Mahalingam 4-Apr-17 2:29am    
post the model

1 solution

@Html.DropDownList("Distric", new SelectList(Model.Select(k => k.Distric)), "Select Distric");
 
Share this answer
 
Comments
Asif_Aziz 4-Apr-17 6:18am    
Thanks bro
Karthik_Mahalingam 4-Apr-17 7:45am    
welcome
Asif_Aziz 4-Apr-17 6:20am    
any idea for value and text property
Karthik_Mahalingam 4-Apr-17 7:45am    
do you have id property
Asif_Aziz 5-Apr-17 5:09am    
yes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900