This is a migrated thread and some comments may be shown as answers.

[Solved] Trouble binding tabstrip to a site map

3 Answers 118 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
William Brown
Top achievements
Rank 1
William Brown asked on 04 Jun 2010, 12:25 AM

Hello,
I am trying to bind my TabStrip to a SiteMap using the demo example.  I am getting errors in the controller on PopulateSiteMap and SiteMapManager (see below).  First, did I miss a step in configuration or is there other code that needs to exist?  Second, can you bind to a site map and include it in a partial view to be shared by all pages? 

 

 

public class AdminTabStripController : Controller

 

{

    [PopulateSiteMap(SiteMapName =

"sample", ViewDataKey = "sample")]

 

 

    public ActionResult SiteMapBinding()

 

        {

 

            if (!SiteMapManager.SiteMaps.ContainsKey("sample"))

 

            {

            SiteMapManager.SiteMaps.Register<XmlSiteMap>(

"sample", sitmap => sitmap.LoadFrom("~/sample.sitemap"));

 

            }

 

            return View();

 

        }

}

 

Thanks for the help

Bill
 

3 Answers, 1 is accepted

Sort by
0
Azeheruddin khan
Top achievements
Rank 1
answered on 05 Jun 2010, 05:21 AM
Hi William,

This is code is fine.Plzs check this code....

 [PopulateSiteMap(SiteMapName = "sample", ViewDataKey = "sample")]
         [SourceCodeFile("Sitemap", "~/sample.sitemap")] ------------------ Add this code
        public ActionResult Index()
        {
            if (!SiteMapManager.SiteMaps.ContainsKey("sample"))
            {
                SiteMapManager.SiteMaps.Register<XmlSiteMap>("sample", sitmap => sitmap.LoadFrom("~/sample.sitemap"));
            } 

            return View();
        }


u have to add some file in extensions and filters folder.If u have not created these folder plzs create it...
 1)Extensions Folder
Add this class file.....   DictionaryExtensions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace sama.Extensions
{
    public static class DictionaryExtensions
    {
        public static T Get<T>(this IDictionary<string, object> instance, string key)
        {
            return instance.ContainsKey(key) ? (T)instance[key] : default(T);
        }

        public static void Set<T>(this IDictionary<string, object> instance, string key, T value)
        {
            instance[key] = value;
        }
    }
}


2)Filters Folder 
Add this class file---- SourceCodeFileAttribute.cs

using System;
using System.Reflection;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using sama.Extensions;

namespace sama.Filters
{
    [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
    public class SourceCodeFileAttribute : FilterAttribute, IResultFilter
    {
        private readonly string caption;
        private readonly string filename;

        public SourceCodeFileAttribute(string caption, string filename)
        {
            this.caption = caption;
            this.filename = filename;
        }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            ViewDataDictionary viewData = filterContext.Controller.ViewData;

            var codeFiles = viewData.Get<Dictionary<string, string>>("codeFiles");

            
        }

        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            // Do Nothing
        }
        
       
    }
}

Keep coding........

Azeheruddin khan

0
William Brown
Top achievements
Rank 1
answered on 09 Jun 2010, 10:11 PM
Hi Azeheruddin,  
 
This worked thanks. Is there a way to use the sitemap provider in the webconfig by ID instead of reading it like a source code file?  
 
so instead of:  
 
    <siteMap defaultProvider="AdminXMLSiteMapProvider" enabled ="true">  
      <providers> 
        <add name ="AdminXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Admin.sitemap" /> 
        <add name ="CaseXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Client.sitemap" /> 
        <add name ="CaseXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Case.sitemap" /> 
      </providers> 
    </siteMap> 
 
and  
 
    <siteMap defaultProvider="AdminXMLSiteMapProvider" enabled ="true">  
      <providers> 
        <add name ="AdminXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Admin.sitemap" /> 
        <add name ="CaseXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Client.sitemap" /> 
        <add name ="CaseXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Case.sitemap" /> 
      </providers> 
    </siteMap> 
 
how can i load from a sitemap I've setup in the webconfig?  
   
   
 
    <siteMap defaultProvider="AdminXMLSiteMapProvider" enabled ="true">  
      <providers> 
        <add name ="AdminXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Admin.sitemap" /> 
        <add name ="CaseXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Client.sitemap" /> 
        <add name ="CaseXMLSiteMapProvider" type="System.Web.XMLSiteMapProvider" siteMapFile ="~/Sitemaps/Case.sitemap" /> 
      </providers> 
    </siteMap> 
 
 
Thanks,  
 
Bill  
 
   
 
 
 
 

 

 

 

 

0
William Brown
Top achievements
Rank 1
answered on 15 Jun 2010, 07:18 PM
Hello Azeheruddin,

Can you give me your thoughts on using a sitemap provider setup in the webconfig? thanks
Tags
TabStrip
Asked by
William Brown
Top achievements
Rank 1
Answers by
Azeheruddin khan
Top achievements
Rank 1
William Brown
Top achievements
Rank 1
Share this question
or