Question

In ASP.NET MVC, I have a defined catch-all route as below:

routes.MapRoute(
    "TagsRoute",
    "tags/{*tags}",
    new { controller = "home", action = "tags"}
);

Inside the controller, I am querying the products which has entered {tags} as below:

public ViewResult(string[] tags) { 

    var model = _repo.Get(tags);

    return View(model);
}

What I am struggling with is how to create a sitemap over this with MVCSiteMapProvider DynamicNodeProviderBase class.

Any idea?

Was it helpful?

Solution

The sitemap node:

<mvcSiteMapNode title="Tags" action="Tags" controller="Home" dynamicNodeProvider="Your.Namespace.TagsDynamicNodeProvider, YourAssemblyName" />

The provider itself would be something along these lines:

public class TagsDynamicNodeProvider
    : DynamicNodeProviderBase
{
    public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
    {
        DynamicNode node = new DynamicNode();
        node.Title = "Some title";
        node.RouteValues.Add("tags", new string[]{"tag1", "tag2"});

        yield return node; 
    }

    public override CacheDescription GetCacheDescription()
    {
        return null;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top