I am working on a MVC5 project where I need to create a sitemap.
I have created my routes using Route Attribute on the controller actions.
I am using a Dynamic node provider as specified in the documentation for MvcSiteMapProvider and it works fine for one of my controllers, however for another one it is displaying the query string paramaters for each mapped route so for example
I am getting
www.url.com?SelectedCulture=en-gb
when I am expecting
www.url.com/en-gb
My routes all work fine and if I use my application it is working fine aswell... It just doesnt create a sitemap which i am expecting
The Dynamic provider that I created is populating the required attribute that matches the route.
Anyone have any ideas?
This is my Mvc.sitemap xml
<mvcSiteMapNode title="ATitle" controller="Parent" action="Index" key="Home">
<mvcSiteMapNode title="ASubTitle" controller="Parent" action="Index" key="CulturePages">
</mvcSiteMapNode>
This is my dynamicNodeProvider
public class SitePagesDynamicProvider : DynamicNodeProviderBase
{
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
using (var ef = new EntityFrameworkRepository())
{
// Create a node for each sites
foreach (var obj in ef.GetIDs();
{
DynamicNode dynamicNode;
dynamicNode = new DynamicNode();
dynamicNode.Title = obj.title;
dynamicNode.ParentKey = "CulturePages";
dynamicNode.RouteValues.Add("SelectedCulture", obj.culture);
yield return dynamicNode;
}
}
}
}
And this is my Controller Action:
[MvcSiteMapNodeAttribute(Title = "Sites", Key = "Sites", ParentKey = "HomePages", DynamicNodeProvider = "TestProject.Models.SitePagesDynamicProvider, TestProject")]
[Route("{SelectedCulture:regex(^([a-z]|[A-Z]){2}-([a-z]|[A-Z]){2}?$)?}/")]
public ActionResult Index(string SelectedCulture)
{
return View();
}
Thanks!