Trevor Hart Trevor Hart - 6 months ago 24
HTML Question

Modifying the contents of EnumDropDownListFor

I'm using an enum to populate a dropdown list using Html.EnumDropDownListFor, the problem is by convention the enum is all capped for what I'm working on, so when it goes to populate the drop down everything is all capped. I looked to see if there was a way to do a toTitleCase or even toLower, something that would look a little less ridiculous, but I've been unable to get it to work (toString just writes the actual html instead, which makes sense).

Is there anyway to do this without writing out the html for a dropdown list? Or am I going to just need to suck it up and write everything out by hand? Just to clarify exactly what I want done, I would prefer to be able to TitleCase everything.

Answer

This fixed the problem

[Display(Name="White")]
WHITE,
[Display(Name = "Black")]
BLACK,
[Display(Name = "Green")]
GREEN,
[Display(Name = "Yellow")]
YELLOW,
[Display(Name = "Specialty")]
SPECIALTY,
[Display(Name = "Oolong")]
OOLONG,
[Display(Name = "Rooibos")]
ROOIBOS,
[Display(Name = "Pu-erh")]
PUERH,
[Display(Name = "Herbal")]
HERBAL