2014-10-17 179 views
2

我有控制器的操作方法显示“选择”默认情况下,下拉列表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")) 

       ) 
+0

查看SelectList的重载 – devqon 2014-10-17 07:24:22

回答

1

没有为new SelectList过载,这需要第四个参数作为“占位符”:

new SelectList(categories.ToList(), "Id", "Name", "-- Select --") 
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> 
              )) 
             ) 
+0

@ SBirthare .Placeholder(“ - Select - ”)它在下拉列表中显示“Select”。但是我希望它在默认情况下显示“Select”...并单击下拉它应该显示值列表 – Hello 2014-10-17 09:26:37

+0

它应该是.Placeholder(“选择”)。SelectedIndex(0)。无论如何非常感谢 – Hello 2014-10-17 10:21:51