Kendo dropdown binding

 ̄綄美尐妖づ 提交于 2019-12-12 04:24:01

问题


I have this enum:

public enum PayTerms
    {       
        [Display(Name = "30")]
        _30 = 1,        
        [Display(Name = "60")]
        _60,        
        [Display(Name = "90")]
        _90,        
        [Display(Name = "120")]
        _120,        
        CAD
    }

Using this template I manage to create dropdown list with proper names:

@model PayTerms?

<div class="k-edit-label">@Html.LabelFor(x => x)</div>
<div class="k-edit-field">
    @(Html.Kendo().DropDownListFor(m => m)
        .BindTo(EnumHelper.GetSelectList(typeof(PayTerms)))
        .OptionLabel("-- Select --"))
</div>

But I have problems with binding. Currently for each value for my enum property selected value in dropdown is "--Select--" How can I bind selected value for the dropdown to enum value?

UPDATE:

Also I have tried EnumHelper.GetSelectList(typeof(Erp.Shared.Contract.PayTerms), Model.Value) but also have no luck


回答1:


Kendo MVC helper has a problem with enums as it can't figure out whether to bind to the integer representation of the enum or the string representation. The default MVC dropdown list has no such problem.

http://www.telerik.com/forums/problem-binding-enum-to-dropdownlist#ZabuB0_2A0OserEwBh_etQ

Try adding an explicit .Value() to the definition:

@(Html.Kendo().DropDownListFor(m => m)
    .BindTo(EnumHelper.GetSelectList(typeof(PayTerms)))
    .Value(((int) Model).ToString())
    .OptionLabel("-- Select --"))


来源:https://stackoverflow.com/questions/39745673/kendo-dropdown-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!