Hello again,
i have the kendo UI for MVC Q3 2012,but inside there is no example folder so i can view the full example for the cascading.
I tried to implement the scenario from the demo,the online example ,but for the moment,the second dropdownlist is not activating when i choose a category.
the cshtml look like this:
<p>
<label for="categories">Categories:</label>
@(Html.Kendo().DropDownList()
.Name("categ")
.OptionLabel("Select category...")
.DataTextField("CategoryName")
.DataValueField("CategoryID")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetCascadeCategories", "Controls");
});
})
)
</p>
<p>
<label for="products">Products:</label>
@(Html.Kendo().DropDownList()
.Name("produc")
.OptionLabel("Select product...")
.DataTextField("ProductName")
.DataValueField("ProductID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCascadeProducts", "Controls")
.Data("filterProducts");
}).ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("categ")
)
<script type="text/javascript">
function filterProducts() {
return {
categories: $("#categ").val()
};
}
</script>
the Code in controller look like this:
public JsonResult GetCascadeCategories()
{
return Json(_categoryRepository.GetAll().Select(c => new { CategoryId = c.CategoryID, CategoryName = c.CategoryName }), JsonRequestBehavior.AllowGet);
}
public JsonResult GetCascadeProducts(string categories)
{
var products = _productRepository.GetAll();
if (!string.IsNullOrEmpty(categories))
{
products = products.Where(p => p.Category.CategoryName == categories);
}
return Json(products.Select(p => new { ProductID = p.ProductID, ProductName = p.ProductName }), JsonRequestBehavior.AllowGet);
}
Or,can you send me a functional example taking data from a real database like Northwind.
Thanks in advance.
i have the kendo UI for MVC Q3 2012,but inside there is no example folder so i can view the full example for the cascading.
I tried to implement the scenario from the demo,the online example ,but for the moment,the second dropdownlist is not activating when i choose a category.
the cshtml look like this:
<p>
<label for="categories">Categories:</label>
@(Html.Kendo().DropDownList()
.Name("categ")
.OptionLabel("Select category...")
.DataTextField("CategoryName")
.DataValueField("CategoryID")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetCascadeCategories", "Controls");
});
})
)
</p>
<p>
<label for="products">Products:</label>
@(Html.Kendo().DropDownList()
.Name("produc")
.OptionLabel("Select product...")
.DataTextField("ProductName")
.DataValueField("ProductID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCascadeProducts", "Controls")
.Data("filterProducts");
}).ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("categ")
)
<script type="text/javascript">
function filterProducts() {
return {
categories: $("#categ").val()
};
}
</script>
the Code in controller look like this:
public JsonResult GetCascadeCategories()
{
return Json(_categoryRepository.GetAll().Select(c => new { CategoryId = c.CategoryID, CategoryName = c.CategoryName }), JsonRequestBehavior.AllowGet);
}
public JsonResult GetCascadeProducts(string categories)
{
var products = _productRepository.GetAll();
if (!string.IsNullOrEmpty(categories))
{
products = products.Where(p => p.Category.CategoryName == categories);
}
return Json(products.Select(p => new { ProductID = p.ProductID, ProductName = p.ProductName }), JsonRequestBehavior.AllowGet);
}
Or,can you send me a functional example taking data from a real database like Northwind.
Thanks in advance.