This is a migrated thread and some comments may be shown as answers.

Cascading in Kendo MVC

1 Answer 240 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Mohammed Adel
Top achievements
Rank 1
Mohammed Adel asked on 24 Jun 2012, 01:01 PM
How can we make a cascading dropdownlist or combobox like the country and cities in kendo.
Thanks in Advance

1 Answer, 1 is accepted

Sort by
0
Samuel
Top achievements
Rank 2
answered on 22 Aug 2012, 12:51 AM
I have a ticket in with Kendo about the documentation (or lack thereof) specifically on DropDownList and DropDownListFor. I've been knocking my head against this brick wall for most of today and finally got a (very simple) case together. Looking at it, I'm not sure I like where it's going and I'd prefer a Parent attribute for the child. In any case, I hope this example helps somewhat (this is a snippet from my View - it's self-contained so you don't need to know anything about even the model) and if anybody wants to expand on it... go ahead. In order to help with the readability, I haven't done anything with BindTo or DataSource other than a commented out line. You could easily .BindTo a SelectList with the appropriate elements.
@(Html.Kendo().DropDownList()
.Name("CountryID")
.Items(items =>
    {
        items.Add().Text("United States").Value("1");
        items.Add().Text("Mexico").Value("2");
        items.Add().Text("Germany").Value("3");
    })
    .DataTextField("Text")
    .DataValueField("Value")
    //.BindTo(myCountries)
.OptionLabel("Select Country")
)
 
@(Html.Kendo().DropDownList()
.Name("CityID")
.Items(items =>
    {
        items.Add().Text("Chicago").Value("1");
        items.Add().Text("Puerto Vallarta").Value("2");
        items.Add().Text("Berlin").Value("3");
        items.Add().Text("San Francisco").Value("1");
        items.Add().Text("Frankfurt").Value("3");
        items.Add().Text("Mexico City").Value("2");
    })
    .DataValueField("Value")
    .DataTextField("Text")
    .CascadeFrom("CountryID")
    .OptionLabel("Select City")
    //.BindTo(myCities)
)
Tags
DropDownList
Asked by
Mohammed Adel
Top achievements
Rank 1
Answers by
Samuel
Top achievements
Rank 2
Share this question
or