Creating dropdownlist in asp.net mvc using enum. Using enum we can populate dropdown list with selectlistitem in mvc. see below example with all steps:

Inside model we need to define
    1. a property of enum type.
    2. a property of SelectedListItem as IEnumerable.
    3. Inside constructor filling Dropdown list from enum.
Model
  1. public class UserModel
  2. {
  3. public Country Country { get; set; }
  4. public IEnumerable<SelectListItem> CountryList { get; set; }
  5. public UserModel()
  6. {
  7. CountryList = Enum.GetNames(typeof(Country)).Select(name => new SelectListItem()
  8. {
  9. Text = name,
  10. Value = name
  11. });
  12. }
  13. }
Enum (County list)
  1. public enum Country
  2. {
  3. India,
  4. USA,
  5. UK,
  6. Canada
  7. }
Action (Creating object of model and return model)
  1. public class HomeController : Controller
  2. {
  3. public ActionResult Country()
  4. {
  5. UserModel model = new UserModel();
  6. return View(model);
  7. }
  8. }
View (Calling mode on top and filling dropdown list)
  1. @model MvcApplication1.Models.UserModel
  2. @{
  3. ViewBag.Title="Country DropDown"
  4. Layout="~/Views/Shared/_Layout.cshtml"
  5. }
  6. Country:
  7. @Html.DropDownListFor(model=>model.Country, Model.CountryList)