This example shows how to databind Telerik PanelBar for ASP.NET MVC.

The required steps are:

  1. Pass an IEnumerable<T> to the view:
    public ActionResult DataBindingToModel()
    {
        NorthwindDataContext northwind = new NorthwindDataContext();
        return View(northwind.Categories);
    }
        
  2. Pass the collection as the first parameter of the BindTo method. The second parameter is an Action<NavigationBindingFactory<PanelBarItem>> which is used to define mappings between objects and PanelBarItem.
    The For<T> method is used to configure the binding. The ItemDataBound method maps properties of T to PanelBarItem. Use the Children method to return the children of T (required to create child panelbar items).
    Here is a panelbar declaration showing how to bind the component to IEnumerable<Category>
    <%= 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;
                        }));
            })
    %>