DropDownList with enums

2 posts, 0 answers
  1. Steven
    Steven avatar
    29 posts
    Member since:
    Jul 2012

    Posted 29 Sep 2012 Link to this post

    I am trying to use a DropDownList with an enum.

    @Html.Kendo().DropDownListFor(model => model.Program) where Program is of type RecyclingProgram which is an Enum.

    How do I get the enum values to:
    1. Display in the drop-down list?
    2. Update the model when it is posted back to the server?
  2. Alexander
    Alexander avatar
    2 posts
    Member since:
    Aug 2012

    Posted 06 Dec 2012 Link to this post

    This thread is kind of old but since it still came up in the search results:

    If the name of your property is ePriority and PriorityEnum is an enum, then the following code will give you you all enum values in the drop down and bind correctly to your model:

    This is equivalent to the following vanilla ASP.NET code (in function, not in the HTML it produces):
    Html.DropDownListFor(m => m.ePriority, new SelectList(Enum.GetNames(typeof(PriorityEnum))))
    The above is courtesy of: http://stackoverflow.com/questions/4656758/mvc3-razor-dropdownlistfor-enums/8538813#8538813
  3. UI for ASP.NET AJAX banner
Back to Top