I have my class RoomType
:
Int32 Id
String Name
String ColorCode
My viewmodel gets a List<Roomtype> RoomTypes
which should be displayed in a dropdown.
Each dropdown option item should have: 1) as title the Name
, 2) as value the Id
, and 3) the style background-color #ColorCode
.
My problems are how to convert this list correctly into a List<SelectListItem>
as required by ASP.NET MVC's DropDownFor
helper, and then to have the correct values inserted for each option.
I've tried to have a new readonly property in my viewmodel, which has a getter RoomtypeSelectList
which returns new SelectList(RoomTypeList)
but I can't get the correct properties to show (Name, Id, Background color).
I'd appreciate some help or pointers in the right direction...