I need to make a cascading combobox with server filtering but I'm having trouble setting the initial value.

The dropdownlist on which the combobox depends looks like this:

@(Html.Kendo().DropDownListFor(model => model.SelectedCompany)
    .Name("UserDetailSelectedCompany")
    .HtmlAttributes(new { style = "width:115px;" })
    .BindTo(Model.CompanyList)
    .Value(Model.SelectedCompany))

Where:

  • model.SelectedCompany is a string
  • Name attribute is set because I need that in the combobox (I've read on the Kendo UI forums I'm not supposed to specify it, but I don't know how to do the cascading combobox without it)
  • Model.CompanyList is a List<string>

An here's the combobox:

@(Html.Kendo().ComboBoxFor(model => model.SelectedDealer)
    .Name("UserDetailSelectedDealer")
    .DataTextField("Name")
    .DataValueField("ID")
    .HtmlAttributes(new { style = "width:325px" })
    .Filter(FilterType.Contains)
    .AutoBind(false)
    .Enable(false)
    .MinLength(3)
    .DataSource(source => source.Read(read => read.Action("GetDealers", "Administration").Data("Administration.GetUserDealerParameters"))
                                .ServerFiltering(true))
    .CascadeFrom("UserDetailSelectedCompany")
    .SelectedIndex(Model.SelectedDealer.ID))

Where:

  • model.SelectedDealer is a Dealer
  • Dealer class contains a Name(string) and an ID (int)
  • MVC action GetDealers return a JSON converted List<Dealer>

Does anyone have an example that demonstrate how I can get this to work? The Kendo UI doc has example for a cascading combobox, server filtering and setting initial value, but not for the 3 at same time.

有帮助吗?

解决方案

You can set the text property of the comboBox. .Text(Model.SelectedDealer)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top