Revision: 37123
Updated Code
at December 4, 2010 03:55 by nkirkes
Updated Code
public static SelectList ToSelectList(this Enum enumeration) { return enumeration.ToSelectList(false); } public static SelectList ToSelectList(this Enum enumeration, bool useSelectedValues) { var values = new Dictionary<string, string>(); foreach (Enum e in Enum.GetValues(enumeration.GetType())) { values.Add(e.GetDisplayName(), e.ToString()); } SelectList list; if (useSelectedValues) { list = new SelectList(values, "value", "key", values[enumeration.ToString()]); } else { list = new SelectList(values, "value", "key"); } return list; }
Revision: 37122
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 4, 2010 03:54 by nkirkes
Initial Code
public static SelectList ToSelectList(this Enum enumeration) { return enumeration.ToSelectList(false); } public static SelectList ToSelectList(this Enum enumeration, bool useSelectedValues) { var values = new Dictionary<string, string>(); foreach (Enum e in Enum.GetValues(enumeration.GetType())) { values.Add(e.GetDisplayName(), e.ToString()); } SelectList list; if (useSelectedValues) { list = new SelectList(values, "value", "key", values[enumeration.ToString()]); } else { list = new SelectList(values, "value", "key"); } return list; }
Initial URL
Initial Description
Initial Title
Enum to SelectList
Initial Tags
Initial Language
C#