显示"Select"默认情况下在 Telerik 下拉列表中 MVC



我有控制器动作方法

public ActionResult _SelectCustomerRole()
{
var categories =_customerService.GetAllCustomerRolesByClientId(_workContext.CurrentClient.Id, true);
 return new JsonResult { Data = new SelectList(categories.ToList(), "Id", "Name") };
}

我想在Telerik下拉菜单中默认显示"选择"文本。。

我的观点是

 @(Html.Telerik().ComboBox()
                .Name("CustomerRoleNames")
                .DataBinding(bindings => bindings.Ajax().Select("_SelectCustomerRole", "Security"))
                .ClientEvents(x => x.OnChange("customerRole_OnChange"))
                )

尝试(参考剑道演示)

.Placeholder("-- Select --")

如下所示:

Html.Kendo().ComboBox().Name("AjaxComboBox").Placeholder("-- Select --")

.OptionLabel("Select State...")

工作示例:

@(Html.Kendo().DropDownList()
        .Name("stateDropdownSelect") 
        .DataTextField("Name") 
        .DataValueField("Name") 
        .DataSource(source => source.Read(read => read.Action("GetAllStates", "Search", new { searchId = Model.SearchId })))
                                          .SelectedIndex(0)
                                          .OptionLabel("Select State...")
                                          .Events(events => events.Change(
                                              @<text>
                                                   function(e) {
                                                   multiselect_change();
                                                   }
                                               </text>
                                              ))
                                          )

new SelectList有一个重载,它将第四个参数作为"占位符":

new SelectList(categories.ToList(), "Id", "Name", "-- Select --")

最新更新