MVC Kendo Combobox从DataSource设置值

问题描述 投票:0回答:1

我有这个代码,如何将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*/)
   )
kendo-grid kendo-asp.net-mvc
1个回答
1
投票

从我的评论:

你应该能够只应用.SelectedIndex(0)而不是值。在声明中

@(Html.Kendo().ComboBox()
              .SelectedIndex(0) //or whatever index you want to apply. 
              ....... removed for brevity
)
© www.soinside.com 2019 - 2024. All rights reserved.