Hello
Hello

Reputation: 25

Display "Select" By default in Telerik drop down list MVC

I have controller action method

public ActionResult _SelectCustomerRole()

{

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

I want to display "Select" Text by default in Telerik drop down..

My view is

 @(Html.Telerik().ComboBox()
                .Name("CustomerRoleNames")

                .DataBinding(bindings => bindings.Ajax().Select("_SelectCustomerRole", "Security"))
                .ClientEvents(x => x.OnChange("customerRole_OnChange"))

                )

Upvotes: 2

Views: 1652

Answers (2)

SBirthare
SBirthare

Reputation: 5137

Try (Refer Kendo Demo)

.Placeholder("-- Select --")

As shown below:

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

Or

.OptionLabel("Select State...")

Working example:

@(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>
                                              ))
                                          )

Upvotes: 3

devqon
devqon

Reputation: 13997

There is an overload for new SelectList which takes a fourth parameter as the 'placeholder':

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

Upvotes: 1

Related Questions