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

Bind Dropdownlist Enum

3 Answers 1031 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mitchell
Top achievements
Rank 1
Mitchell asked on 13 Aug 2014, 11:25 AM
Hi,

I'm trying to bind a Kendo.Dropdownlist to an enum in MVC but cant seem to get it working. It binds OK to get the values but when I change the value its not reflected in the ViewModel. I have attached two screenshots of my editor template (one working and one not). The one that works use the built in EnumDropdownListFor but this doesn't have the styling like the Kendo UI. Any ideas how i can get the Kendo dropdown to work?

@model CapType

@{
    var enumItems = EnumHelper.GetSelectList(typeof(CapType));

    var options = new SelectList(enumItems, "Value", "Text", Model);
}

@(Html.Kendo().DropDownListFor(m => Model)
              .Name("eCapType")
      .BindTo(options))

3 Answers, 1 is accepted

Sort by
0
Mitchell
Top achievements
Rank 1
answered on 13 Aug 2014, 01:40 PM
Right I have fixed this now. Not quite sure why, but it seems to work :)

@model CapType

@Html.Kendo().DropDownListFor(m => Model).BindTo(EnumHelper.GetSelectList(typeof(CapType)))
0
Nga
Top achievements
Rank 1
answered on 19 Nov 2014, 07:57 AM
also found this works
@Html.Kendo().DropDownListFor(m => m.DayOfWeek).BindTo(EnumHelper.GetSelectList(Model.DayOfWeek.GetType(), Model.DayOfWeek)).OptionLabel("Select Day of Week..")
0
Jason
Top achievements
Rank 1
answered on 13 Aug 2015, 03:14 PM

This was very helpful. I was banging my head with other examples.

I use VB, So I will add my VB

in partial view

@modeltype [your enum]

@Html.Kendo().DropDownListFor(Function(model) model).BindTo(EnumHelper.GetSelectList(GetType([your enum])))​

 

Tags
DropDownList
Asked by
Mitchell
Top achievements
Rank 1
Answers by
Mitchell
Top achievements
Rank 1
Nga
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or