Telerik Extensions for ASP.NET MVC

SiteMap Binding

Theme: vista

About this example

This example shows how to configure Telerik TabStrip 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 TabStrip. The first overload requires only the sitemap's name. The second overload requires the sitemap name and an Action<TabStripItem>, which you can use to set properties for each databound item.
    Both overloads will set the RouteName, ControllerName, ActionName, Url properties of the tabstrip item, if they are set for the corresponding SiteMapNode object.
    <%= Html.Telerik().TabStrip()
           .Name("TabStrip")
           .BindTo("SiteMapName")
    %>
            
    or ...
    <%= Html.Telerik().TabStrip()
            .Name("TabStrip")
            .BindTo("SiteMapName", (item, siteMapNode) =>
            {
                item.Selected = siteMapNode.Action == "Index";
            })
    %>