C# Enum Values as Json ASP.NET Web API ResponseBy Patrick Sullivan on Nov 11, 2014
I did not have the easiest time Googling around for this so I thought I would post it. As simple as it may be may be it might help someone solve there issue more quickly.
So I created this api method to return me the values in an array of objects with and id (which is the value of the item in the enum) and a name (which is the display name of the item in the enum). Here is my method from a Web API controller:
Enum.GetValues(typeof(USTimeZones)) to get an array of the values in the enum and then I add an object to my array that is the item from the array casted into an int and then the item casted into a string to get the name.