剑道下拉绑定 [英] Kendo dropdown binding
问题描述
我有这个枚举:
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>
但是我在绑定时遇到问题.当前,对于我的枚举属性的每个值,下拉列表中的选定值均为"--Select--" 如何将下拉列表中的选定值绑定到枚举值?
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?
更新:
我也尝试过EnumHelper.GetSelectList(typeof(Erp.Shared.Contract.PayTerms), Model.Value)
但也没有运气
Also I have tried EnumHelper.GetSelectList(typeof(Erp.Shared.Contract.PayTerms), Model.Value)
but also have no luck
推荐答案
Kendo MVC助手的枚举存在问题,因为它无法确定是绑定到枚举的整数表示形式还是字符串表示形式.默认的MVC下拉列表没有此问题.
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/问题绑定枚举到下拉列表#ZabuB0_2A0OserEwBh_etQ
尝试在定义中添加一个显式的.Value():
Try adding an explicit .Value() to the definition:
@(Html.Kendo().DropDownListFor(m => m)
.BindTo(EnumHelper.GetSelectList(typeof(PayTerms)))
.Value(((int) Model).ToString())
.OptionLabel("-- Select --"))
这篇关于剑道下拉绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!