I have implemented this https://github.com/maartenba/MvcSiteMapProvider/wiki/Defining-sitemap-nodes-using-IDynamicNodeProvider
Edit: this is my class
public class MyDynamicNodeProvider
: DynamicNodeProviderBase
{
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
webdata storeDB = new webdata();
var returnValue = new List<DynamicNode>();
foreach (var article in storeDB.SiteContents)
{
DynamicNode enode = new DynamicNode();
enode.Title = article.ArticleTitle;
enode.ParentKey = "ArticleID";
enode.Url = "ArticleDetails/" + article.ArticleID + "/" + article.ArticleAlias;
//Specify Controller and Action name
enode.Controller = "SiteContents";
enode.Action = "ArticleDetails";
enode.RouteValues.Add("id", article.ArticleID);
returnValue.Add(enode);
yield return enode;
}
}
}
Edit:this is my sitemap file
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="About Us" controller="Menu" action="AboutUs">
<mvcSiteMapNode title="Profile" controller="Menu" action="Profile"/>
<mvcSiteMapNode title="History" controller="Menu" action="History"/>
</mvcSiteMapNode>
<mvcSiteMapNode title="Article" controller="SiteContents" action="ArticleDetails" key="ArticleID">
<mvcSiteMapNode title="Details" dynamicNodeProvider="Myproject.Models.MyDynamicNodeProvider, Myproject" />
</mvcSiteMapNode>
Edit: The second controller which I have (SiteContentsController )
public ActionResult ArticleDetails(int? id, string slug)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
SiteContents siteContents = db.SiteContents.Find(id);
if (siteContents == null)
{
return HttpNotFound();
}
if (string.IsNullOrWhiteSpace(slug))
{
var alias = db.SiteContents.First(p => p.ArticleID == id).ArticleAlias;
return RedirectToAction("ArticleDetails", new { id = id, slug = alias });
}
return View(siteContents);
}
The url I would like to have (which work but it doesn't bring the sitemap
is http://localhost:xxxx/ArticleDetails/1/Quality_Policy
and I call the sitemap at my layoutpage
@Html.MvcSiteMap().SiteMapPath()
Edit: My route.config
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(name: "Articles", url: "ArticleDetails/{id}/{slug}", defaults: new { controller = "SiteContents", action = "ArticleDetails", id = UrlParameter.Optional, slug = UrlParameter.Optional });
routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}", defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional});
}
I also have some static nodes which work ok. The problem is that with in dynamic pages returns nothing and I dont get any error message thank you