【问题标题】:Kendo ui mvc dropdownlistfor with boolean type value using Entity FrameworkKendo ui mvc dropdownlistfor 使用实体框架的布尔类型值
【发布时间】:2017-11-27 11:06:45
【问题描述】:
@Html.Kendo().DropDownListFor(model => model.Is_Active)
//instead of @Html.EditorFor(model => model.Is_Active)"
我正在使用实体 crud 操作,Is_Active 是一个布尔类型值。在生成编辑视图时,它会显示下拉列表,其中代码是
@Html.EditorFor(model => model.Is_Active)
我想在 kendo ui 中使用
更改它
@Html.Kendo().DropDownListFor(model => model.Is_Active)
但它显示空白下拉列表 - 请提供回复
【问题讨论】:
标签:
kendo-ui
kendo-asp.net-mvc
kendo-treeview
kendo-ui-mvc
【解决方案1】:
您需要为 DropDownList 指定 DataSource,否则其中没有项目列表。为此,您使用 .BindTo()。
Html.EditorFor() 之所以有效,是因为布尔值的内部实现会为您创建 True/False 项目列表。
当您明确定义 DropDownList 时,您需要使用 .BindTo() 提供值和潜在值列表,即
@{
var boolDataSource = new List<SelectListItem>()
{
new SelectListItem() { Text = "True", Value = "True" },
new SelectListItem() { Text = "False", Value = "False" }
};
// Or however/wherever you want to define the list of items that the DropDownList uses.
}
@Html.Kendo().DropDownListFor(model => model.Is_Active).BindTo(boolDataSource)