Using telerik Panel Bar
Html.Telerik().PanelBar()
.Name("PanelBar")
.BindTo(Model, mappings =>
{
mappings.For<Category>(binding => binding
.ItemDataBound((item, category) =>
{
item.Text = category.CategoryName;
})
.Children(category => category.Products));
mappings.For<Product>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.ProductName;
}));
})
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-panelbar-data-binding.html
What I need is to generate a URL based on categoryID
and productID
i.e. :
.Children(category => category.Products));
mappings.For<Product>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.ProductName;
item.Url = (Get at the parent to get the categoryid somehow) + "/Details/" + product.productID;
}));
But I can't figure out how I can access any of the category fields.
And I can't get it from product because it will be one-many, and i'll have product.Categories.
linq methods
Cheers
Although I didn't want to, I managed to store the value like this:
mappings.For<Category>(binding => binding
.ItemDataBound((item, category) =>
{
item.Text = category.CategoryName;
item.ActionName = category.CategoryID.ToString();
})
.Children(category => category.Products));
mappings.For<Product>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.ProductName;
item.Url = item.Parent.ActionName + "/Detail/" + product.ProductID;
}));
Wonder if anyone ends up with a cleaner solution