In ASP.NET MVC 2, I'd like to write a very simple dropdown list which gives static options. For example I'd like to provide choices between "Red", "Blue", and "Green".
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
With "Please select one Item"
Derived from the codes: Master Programmer && Joel Wahlund ;
King Reference : https://stackoverflow.com/a/1528193/1395101 JaredPar ;
Thanks Master Programmer && Joel Wahlund && JaredPar ;
Good luck friends.
Hi here is how i did it in one Project :
I hope it helps Somebody. Thanks
See this MSDN article and an example usage here on Stack Overflow.
Let's say that you have the following Linq/POCO class:
And let's say that you have the following model:
And, finally, let's say that you have the following list of colors. They could come from a Linq query, from a static list, etc.:
In your view, you can create a drop down list like so:
Avoid of lot of fat fingering by starting with a Dictionary in the Model
In the View convert it to a list for display
Or if it's from a database context you can use
or you can write no classes, put something like this directly to the view.