Some enumeration types are defined in the recent project, and you need to pass the enumerated key values to the front end for making the drop-down menu.
1, first defines the enumeration type
Public enum int {
Sick leave = 1,
Leave = 2,
Marriage leave = 3,
Maternity leave = 4,
Bereavement = 5
}
Here I created a new console application that looked at the output effect,
public static void Main (string[] args)
{
foreach (var item in Enum.getvalues (typeof (absence type)))
{
Console.WriteLine (String. Format ("{0}={1}", item. ToString (), Convert.ToInt32 (item));
var mm = (leave type) Enum.parse (typeof (absence type), item. ToString ());
Console.WriteLine (mm);
}
Console.read ();
}
The effect is really what I want.
2. Then create a new object
/// <summary> ///type of Leave/// </summary> Public classOffweektype {/// <summary> ///type name/// </summary> Public stringName {Get;Set; } /// <summary> ///Type value/// </summary> Public stringValue {Get;Set; } }
Assigning a value to an object
/// <summary> ///get all the leave types/// </summary> /// <returns></returns> PublicResultentity<list<offweektype>>Getoffworktype () {List<OffWeekType> list =NewList<offweektype>(); foreach(varValueinchEnum.getvalues (typeof(leave type))) { //var result = string. Format ("Name: ' {0} ', value:{1}", Value. ToString (), Convert.ToInt32 (value)); //Traversing enumeration TypesOffweektype type =NewOffweektype {Name=value. ToString (), Value=Convert.ToInt32 (value). ToString (),}; List. ADD (type); } returngetresultentity (list); }
Using code snippet traversal, enum type enum