Created
September 15, 2012 02:24
-
-
Save keroger2k/3726104 to your computer and use it in GitHub Desktop.
EnumToSelectList
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 SelectList ToSelectList<TEnum>(this TEnum enumObj) | |
| { | |
| var values = from TEnum e in Enum.GetValues(typeof(TEnum)) | |
| select new { Value = e, Text = e.ToString() }; | |
| return new SelectList(values, "Value", "Text", enumObj); | |
| } |
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 enum QueryTypes | |
| { | |
| Web, | |
| Images, | |
| Documents | |
| } | |
| public class HomeController : Controller | |
| { | |
| public ActionResult Index() | |
| { | |
| ViewBag.Select = typeof(QueryTypes).ToSelectList(); | |
| return View(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment