블로그 이미지
Sunny's

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

Notice

2009. 4. 28. 09:08 .NET Framework

asp.net mvc 1.0 IEnumerable for struct(enum)

 public class EnumHelper
    {
        public static IEnumerable<ListItem> Enumerate<T>() where T : struct
        {
            foreach (int value in Enum.GetValues(typeof(T)))
                yield return new ListItem(value.ToString(), Enum.GetName(typeof(T), value));
        }
    }

    public class ListItem
    {
        public string Value{get;set;}
        public string Text{get;set;}

        public ListItem(string v, string t)
        {
            this.Value = v;
            this.Text = t;
        }
    }



SelectList(EnumHelper.Enumerate<ProjTaskState>(), "Value", "Text");


posted by Sunny's