If I have the following enum
public enum EmployeeType
{
Manager = 1,
TeamLeader,
Senior,
Junior
}
and I have DropDownList
I wrote a helper function to give me a dictionary that I can bind:
public static Dictionary GetDictionaryFromEnum()
{
string[] names = Enum.GetNames(typeof(T));
Array keysTemp = Enum.GetValues(typeof(T));
dynamic keys = keysTemp.Cast();
dynamic dictionary = keys.Zip(names, (k, v) => new {
Key = k,
Value = v
}).ToDictionary(x => x.Key, x => x.Value);
return dictionary;
}