显示“选择”默认情况下,在Telerik下拉列表MVC中

时间:2014-10-17 07:22:08

标签: asp.net-mvc combobox telerik

我有控制器动作方法

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"))

                )

2 个答案:

答案 0 :(得分:3)

尝试(参考Kendo Demo

.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>
                                              ))
                                          )

答案 1 :(得分:1)

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

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