Kendo Grid DropDownList不起作用

时间:2018-07-23 07:27:44

标签: c# asp.net-mvc-4 kendo-grid kendo-asp.net-mvc

无法在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 = "" })
    )

及其绑定为文本框,而不是下拉列表。 如何使其绑定下拉列表? 注意:这些值在数据库中没有关系,我只需要按列并通过代码进行设置即可。

1 个答案:

答案 0 :(得分:0)

这并不像您担心的那么简单。 整个实现可以在documentation of Telerik中找到。

在几句话中,您必须:

  1. 创建一个对象(文本值或ID标签)以绑定到您的列
  2. 为此类创建编辑器模板

    @(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.
    )
    
  3. 使用[UIHint("ObjectEditor")]

  4. 装饰您的财产
相关问题