Kendo UI MVC下拉列表使用实体框架具有布尔类型值


 @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) 

但显示空白的下拉列表 - 请提供响应

您需要为下拉列表指定数据源,否则没有项目列表。您为此使用.bindto()。

html.editorfor()起作用,因为布尔的内部实现为您创建了True/False项目列表。

明确定义下拉列表时,您需要使用.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)

最新更新