Telerik Extensions for ASP.NET MVC

Version Q2 2012, released 06/07/2012

About this example ASPXRazor

This example shows how to configure Telerik PanelBar for ASP.NET MVC to bind to a SiteMap.

The required steps are:

  1. Define a sitemap and add it to the ViewData. This example is using the SiteMapManager which allows you to create sitemaps. The PopulateSiteMap attribute adds a registered sitemap to the ViewData with a key specified by the ViewDataKey property:
    [PopulateSiteMap(SiteMapName = "sample", ViewDataKey = "sample")]
    [SourceCodeFile("Sitemap", "~/sample.sitemap")]
    public ActionResult SiteMapBinding()
    {
        if (!SiteMapManager.SiteMaps.ContainsKey("sample"))
        {
            SiteMapManager.SiteMaps.Register<XmlSiteMap>("sample", sitmap => sitmap.LoadFrom("~/sample.sitemap"));
        }
    
        return View();
    }
            
  2. Use one of the overloads of the BindTo method to bind the PanelBar. The first overload requires only the sitemap's name. The second overload requires the sitemap name and an Action<PanelBarItem>, which you can use to set properties for each databound item.
    Both overloads will set the RouteName, ControllerName, ActionName, Url properties of the PanelBar item, if they are set for the corresponding SiteMapNode object.
    <%= Html.Telerik().PanelBar()
           .Name("PanelBar")
           .BindTo("SiteMapName")
    %>
            
    or ...
    <%= Html.Telerik().PanelBar()
            .Name("PanelBar")
            .BindTo("SiteMapName", (item, siteMapNode) =>
            {
                item.Selected = siteMapNode.Action == "Index";
            })
    %>
            

Interested in HTML5 and mobile-powered ASP.NET MVC apps?

Experience the next generation UI and framework for ASP.NET MVC development by downloading trial evaluation copy of Kendo UI Complete for ASP.NET MVC. Jumpstart your development with the available learning resources.

The differences between Telerik MVC Extensions and Kendo UI Complete for ASP.NET MVC, and their licensing models are explained here and here.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Other Demos: