将枚举值直接绑定到Kendo DropDownList

时间:2015-12-16 13:53:38

标签: asp.net-mvc enums kendo-ui kendo-asp.net-mvc html.dropdownlistfor

我有一个枚举类,并尝试将值绑定到Kendo DropDownListFor,如下所示。但是,只有" undefined"因为ddl和I的值无法管理枚举值。有可能吗?

枚举:

public enum Country
{
    [Description("United States")]
    US = 1,
    [Description("United Kingdom")]
    UK = 2,
    [Description("New Zealand")]
    NewZealand = 3,
    [Description("France")]
    France = 4,
    [Description("Germany")]
    Germany = 5
}


型号:

public class Tourist
{
    [Key]
    public int ID { get; set; }

    //I used enums like that in order to display the multiple word values i.e. United States
    public Country Country { get; set; }

    [NotMapped]
    public string CountryeName
    {
        get { return MyEnumHelper.GetDescription(Country); }
    }

    //code omitted for brevity
}


查看:

@(Html.Kendo().DropDownListFor(m => m.Country)
    .DataTextField("Country")
    .DataValueField("Country")
    .OptionLabel("Select")
    .BindTo(Enum.GetNames(typeof(Country)).ToList())
)

0 个答案:

没有答案