I would like to declare a dropdown box in a view in an ASP.NET MVC application, for letting the user select a lookup value. I know how to declare plain text boxes but is there an official helper for declaring dropdown boxes (date time pickers and the rest)?.
I also don’t know what structure I should pass to my view for giving the values to the dropdown box. I assume I need both an id and a description.
Finally, how do I pass the selected id from the dropdown box back to my action in the controller?
If you have a table of Product Types with description and a value ( id ) that you want to map to your dropdown then do the following inside your action in the controller.
Then inside your view type the following
TypeID and Description refers to the properties of your object of type ProductType
Also, you might not find Html.DropDownList if you have an older version of MVC installed, make sure you have a Beta+ version before you try this out.