【问题标题】:Display "Select" By default in Telerik drop down list MVC在 Telerik 下拉列表 MVC 中默认显示“选择”
【发布时间】:2014-10-17 07:22:07
【问题描述】:

我有控制器动作方法

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

                )

【问题讨论】:

  • 查看 SelectList 的重载

标签: asp.net-mvc combobox telerik


【解决方案1】:

试试(参考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>
                                              ))
                                          )

【讨论】:

  • @ SBirthare .Placeholder("-- Select --") 它在下拉列表中显示“选择”。但我希望它默认显示“选择”...并单击下拉它应该显示值列表
  • 应该是 .Placeholder("Select").SelectedIndex(0)。无论如何,非常感谢你
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多