I'm trying to use the cascading dropdownlist but I have a strange behaviour when the second dropdown datasource is an empty list (which happens sometimes in my project). The second dropdownlist is not clear and keeps the old data previously selected.
Example :
First dropdown is loaded with some "categories"
I select "Category1" in the first dropdown => second dropdown is loaded correctly with 2 "products"
I select one product "Product1" in my second dropdown => OK
I select "Category2" in the first dropdown which contains no products (the controller return an empty list) => "Product1" is still selected in the second dropdown!! The data is not cleared!
Here's my code :
Example :
First dropdown is loaded with some "categories"
I select "Category1" in the first dropdown => second dropdown is loaded correctly with 2 "products"
I select one product "Product1" in my second dropdown => OK
I select "Category2" in the first dropdown which contains no products (the controller return an empty list) => "Product1" is still selected in the second dropdown!! The data is not cleared!
Here's my code :
<
div
class
=
"row"
>
<
span
class
=
"editor-label"
>
@Html.LabelFor(model => model.Categorie, true, true)
</
span
><
span
class
=
"editor-field"
>
@(Html.Kendo().DropDownListFor(model => model.IdCategorie)
.Name("CategorieDropDown")
.DataTextField("Nom")
.DataValueField("IdCategorie")
.OptionLabel("Sélectionner une catégorie")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllCategories", "Article");
}).ServerFiltering(true);
})
.HtmlAttributes(new { style = "width:250px" })
)
</
span
>
</
div
>
<
div
class
=
"row"
>
<
span
class
=
"editor-label"
>
@Html.LabelFor(model => model.SousCategorie, true, true)
</
span
><
span
class
=
"editor-field"
>
@(Html.Kendo().DropDownListFor(model => model.IdSousCategorie)
.Name("SousCategorieDropDown")
.DataTextField("Nom")
.DataValueField("IdCategorie")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetAllSousCategories", "Article")
.Data("filterCategorie");
})
.ServerFiltering(true);
})
.OptionLabel("Sélectionner une sous catégorie")
.Enable(false)
.AutoBind(false)
.CascadeFrom("CategorieDropDown")
.HtmlAttributes(new { style = "width:250px" })
)
<
script
>
function filterCategorie() {
return {
idCategorie: $("#CategorieDropDown").val()
};
}
</
script
>
</
span
>
</
div
>