Kendo 网格下拉列表不起作用
Kendo Grid DropDownList not work
无法在 kendo 网格中绑定 DropDownList。
如果它不在网格内,它工作正常。
我尝试使用
@(Html.Kendo().DropDownList()
.Name("RegionId")
.OptionLabel("[|[Select...]|]")
.DataTextField("Name")
.DataValueField("Id")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("FindAll", "region")
.Data("filterRegion");
})
.ServerFiltering(true);
})
.HtmlAttributes(new { @required = "" })
.Enable(false)
.AutoBind(false)
.CascadeFrom("CountryId")
.ValuePrimitive(true).HtmlAttributes(new { @required = "" })
)
及其绑定为文本框,而不是下拉列表。
如何让它绑定下拉列表?
注意:这些值在数据库中没有关系我只需要列并通过代码制作它。
这恐怕没有你想的那么简单。
整个实现可以在 documentation of Telerik.
中找到
简而言之,您必须:
- 创建一个对象(Text-Value 或 Id-Label)以绑定到您的列
为此class
创建一个编辑器模板
@(Html.Kendo().DropDownList()
.Name("Employee") // The name of the widget should be the same as the name of the property.
.DataValueField("EmployeeID") // The value of the dropdown is taken from the EmployeeID property.
.DataTextField("EmployeeName") // The text of the items is taken from the EmployeeName property.
.BindTo((System.Collections.IEnumerable)ViewData["employees"]) // A list of all employees which is populated in the controller.
)
用[UIHint("ObjectEditor")]
装饰你的属性
无法在 kendo 网格中绑定 DropDownList。 如果它不在网格内,它工作正常。 我尝试使用
@(Html.Kendo().DropDownList()
.Name("RegionId")
.OptionLabel("[|[Select...]|]")
.DataTextField("Name")
.DataValueField("Id")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("FindAll", "region")
.Data("filterRegion");
})
.ServerFiltering(true);
})
.HtmlAttributes(new { @required = "" })
.Enable(false)
.AutoBind(false)
.CascadeFrom("CountryId")
.ValuePrimitive(true).HtmlAttributes(new { @required = "" })
)
及其绑定为文本框,而不是下拉列表。 如何让它绑定下拉列表? 注意:这些值在数据库中没有关系我只需要列并通过代码制作它。
这恐怕没有你想的那么简单。 整个实现可以在 documentation of Telerik.
中找到简而言之,您必须:
- 创建一个对象(Text-Value 或 Id-Label)以绑定到您的列
为此class
创建一个编辑器模板@(Html.Kendo().DropDownList() .Name("Employee") // The name of the widget should be the same as the name of the property. .DataValueField("EmployeeID") // The value of the dropdown is taken from the EmployeeID property. .DataTextField("EmployeeName") // The text of the items is taken from the EmployeeName property. .BindTo((System.Collections.IEnumerable)ViewData["employees"]) // A list of all employees which is populated in the controller. )
用
[UIHint("ObjectEditor")]
装饰你的属性