This is a migrated thread and some comments may be shown as answers.

Show DisplayAttribute Value in DropDownList

2 Answers 552 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 26 Jul 2014, 07:38 AM
My Model uses the following Enum :
    public enum Priority {
        [Display(Name = "Niedrig")]
        Low,
        [Display(Name = "Normal")]
        Normal,
        [Display(Name = "Hoch")]
        High
    }


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 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 30 Jul 2014, 06:35 AM
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.

Regards,
Vladimir Iliev
Telerik
 

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.

 
0
Jimmie
Top achievements
Rank 2
answered on 03 Jun 2015, 11:10 PM

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.

Tags
DropDownList
Asked by
Christian
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Jimmie
Top achievements
Rank 2
Share this question
or