Show DisplayAttribute Value in DropDownList

3 posts, 1 answers
  1. Christian
    Christian avatar
    33 posts
    Member since:
    Jul 2014

    Posted 26 Jul 2014 Link to this post

    My Model uses the following Enum :
        public enum Priority {
            [Display(Name = "Niedrig")]
            [Display(Name = "Normal")]
            [Display(Name = "Hoch")]

    I want to show the DisplayName Attribute Value in the DropDownList.

    How must this line be changed in order to achive this?
    @Html.Kendo().DropDownListFor(model => model.Priority).BindTo(Enum.GetNames(typeof(Priority))).Value(Model.Priority.ToString())

  2. Answer
    Vladimir Iliev
    Vladimir Iliev avatar
    2190 posts

    Posted 30 Jul 2014 Link to this post

    Hi Christian,

    For convenience I created small example of the correct way of localizing the Enum items and using them as data for the DropDownList - you can find the demo attached to the current thread.

    Vladimir Iliev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Jimmie
    Jimmie avatar
    20 posts
    Member since:
    Nov 2008

    Posted 03 Jun 2015 Link to this post

    I know this post almost a year old, but there is an easier way to get the Display Name attribute values to work with the Kendo DropDownList using the EnumHelper class:

     @Html.Kendo().DropDownListFor(model => model.Priority).BindTo(EnumHelper.GetSelectList(typeof(Priority))).Value(Model.Priority.ToString())

     This will work as long you are using MVC 5.1 or later.

Back to Top