Bind Dropdownlist Enum

4 posts, 0 answers
  1. Mitchell
    Mitchell avatar
    5 posts
    Member since:
    Jul 2014

    Posted 13 Aug 2014 Link to this post

    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))
  2. Mitchell
    Mitchell avatar
    5 posts
    Member since:
    Jul 2014

    Posted 13 Aug 2014 in reply to Mitchell Link to this post

    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)))
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Nga
    Nga avatar
    8 posts
    Member since:
    Oct 2012

    Posted 19 Nov 2014 in reply to Mitchell Link to this post

    also found this works
    @Html.Kendo().DropDownListFor(m => m.DayOfWeek).BindTo(EnumHelper.GetSelectList(Model.DayOfWeek.GetType(), Model.DayOfWeek)).OptionLabel("Select Day of Week..")
  5. Jason
    Jason avatar
    1 posts
    Member since:
    Feb 2014

    Posted 13 Aug 2015 Link to this post

    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])))​

     

Back to Top
UI for ASP.NET MVC is VS 2017 Ready