为了账号安全,请及时绑定邮箱和手机立即绑定

剑道网格 DropDownList 不起作用

剑道网格 DropDownList 不起作用

C#
HUX布斯 2021-10-23 16:40:46
无法在剑道网格中绑定 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 = "" })    )并将其绑定为文本框,而不是下拉列表。如何让它绑定下拉列表?注意:值在数据库中没有关系我只需要列并通过代码制作。
查看完整描述

1 回答

?
慕工程0101907

TA贡献1887条经验 获得超5个赞

这并不像你想象的那么简单,我害怕。整个实现可以在Telerik的文档中找到。


简而言之,您必须:


创建一个对象(Text-Value 或 Id-Label)以绑定到您的列

为这个类创建一个编辑器模板


@(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")]


查看完整回答
反对 回复 2021-10-23
  • 1 回答
  • 0 关注
  • 125 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信