Last active
December 26, 2015 12:09
-
-
Save danielmackay/7149342 to your computer and use it in GitHub Desktop.
MVC select list helper for enums. #mvc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SelectListExt | |
{ | |
public static SelectList ToSelectList<TEnum>(this TEnum enumObj) | |
where TEnum : struct, IComparable, IFormattable, IConvertible | |
{ | |
var values = from TEnum e in Enum.GetValues(typeof(TEnum)) | |
select new { Id = e, Name = e.ToString() }; | |
return new SelectList(values, "Id", "Name", enumObj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment