来自数据源的MVC Kendo组合框设置值

时间:2019-02-14 16:16:28

标签: kendo-grid kendo-asp.net-mvc

我有这段代码,如何将Value属性设置为DataSource中的第一个元素?

  @(Html.Kendo().ComboBox()
                          .Name("cboShip")
                          .Placeholder("Select Ship...")
                          .Filter(FilterType.Contains)
                          .DataTextField("ShipName")
                          .DataValueField("ShipId")
                          .DataSource(s =>
                          {
                            s.Read(read => { read.Action("GetShips", "Filter"); });
                          })
                          .Events(events => events.Change("cboShipMultiChange"))
                         .Value('' /*????? I want to get the first element from the DataSource and use it in here*/)
   )

1 个答案:

答案 0 :(得分:1)

根据我的评论:

您应该只可以应用.SelectedIndex(0)而不是值。在声明中

@(Html.Kendo().ComboBox()
              .SelectedIndex(0) //or whatever index you want to apply. 
              ....... removed for brevity
)