猿问

剑道网格 DropDownList 不起作用

无法在剑道网格中绑定 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 = "" })

    )

并将其绑定为文本框,而不是下拉列表。如何让它绑定下拉列表?注意:值在数据库中没有关系我只需要列并通过代码制作。


HUX布斯
浏览 126回答 1
1回答

慕工程0101907

这并不像你想象的那么简单,我害怕。整个实现可以在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")]
随时随地看视频慕课网APP
我要回答