Creating Html.DropDownList with Values

asp.net-mvc-3 c# entity-framework linq-to-entities razor

Question

I am trying to create a dropdown list that contains values from my data model. I cannot seem to get this to work inside of my view:

@Html.DropDownList("Program Types", 
new SelectList(Model.Select(x => x.ProgramType.ProgramType).Distinct().OrderBy(x => x),
Model.Select(x => x.ProgramType.ProgramTypeId).Distinct().OrderBy(x => x)))
1
1
8/24/2012 8:29:20 PM

Accepted Answer

Take a look at this example:

How to write a simple Html.DropDownListFor()

It doesn't get any simpler than that and you can adjust this example to your case quite easily.

Hope this is of help to you & good luck!

2
5/23/2017 12:09:17 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow