1

I am new to MVC. I created a simple dropdown list using the following code

Model:

    public enum weltype 
    {  
        Physical = 1, 
        Career =2
    }

controller:

            IEnumerable<weltype> Wellbeings = Enum.GetValues(typeof(weltype))
                                                  .Cast<weltype>();
            model.WellList = from welbeing in Wellbeings
                             select new SelectListItem
                             {
                                 Text = welbeing.ToString(),
                                 Value = ((int)welbeing).ToString()
                             };
            return View(model);

view:

        @Html.LabelFor(model => model.WellbeingID)
        @Html.DropDownListFor(model => model.WellbeingID, Model.WellList)

my problem here is i need to get the enum values from the database using linq or whatever feasible. What is the easiest way to do it?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • This is how to get the enum string from the corresponding enum value: http://stackoverflow.com/q/2650080. Are you sure you don't want to include `weltype` as a table in the database, so that you can just do a simple join/lookup? – Robert Harvey Nov 13 '13 at 17:58
  • weltype is a table in a database, i dont need enum string but i need to get weltype values from the database instead of hardcoding it. – user2988917 Nov 13 '13 at 19:14
  • If all you want is an IEnumerable, why not use a Dictionary? – Sam Nov 18 '13 at 14:16

0 Answers0