Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Controller Name=News
- Home
- News
- first //id=1
- second //id=2
- third // id=3
- About
- <mvcSiteMapNode title="Home" controller="Home" action="Index">
- <mvcSiteMapNode title="News" controller="News" action="Index" key="News">
- </mvcSiteMapNode>
- <mvcSiteMapNode title="About" controller="About" action="Index"/>
- [MvcSiteMapNode(Title = "News", ParentKey = "News")]
- public ActionResult News(int id)
- {
- ViewBag.id = id;
- return View();
- }
- <mvcSiteMapNode title="News" controller="News" action="News" preservedRouteParameters="id"/>
- [MvcSiteMapNode(Title = "News", ParentKey = "News", PreservedRouteParameters = "id")]
- public ActionResult News(int id)
- {
- ViewBag.id = id;
- return View();
- }
- <mvcSiteMapNode title="Article 1" controller="News" action="News" id="1"/>
- <mvcSiteMapNode title="Article 2" controller="News" action="News" id="2"/>
- <mvcSiteMapNode title="Article 3" controller="News" action="News" id="3"/>
- [MvcSiteMapNode(Title = "Article 1", ParentKey = "News", Attributes = @"{ ""id"": 1 }")]
- [MvcSiteMapNode(Title = "Article 2", ParentKey = "News", Attributes = @"{ ""id"": 2 }")]
- [MvcSiteMapNode(Title = "Article 3", ParentKey = "News", Attributes = @"{ ""id"": 3 }")]
- public ActionResult News(int id)
- {
- ViewBag.id = id;
- return View();
- }
- <mvcSiteMapNode title="News" controller="News" action="Index" key="News">
- // Setup definition node in XML (won't be in the SiteMap)
- // Any attributes you put here will be the defaults in the dynamic node provider, but can be overridden there.
- <mvcSiteMapNode dynamicNodeProvider="MyNamespace.NewsDynamicNodeProvider, MyAssembly" controller="News" action="News"/>
- </mvcSiteMapNode>
- // Setup definition node as a .NET Attribute (won't be in the SiteMap)
- // Any properties you put here will be the defaults in the dynamic node provider, but can be overridden there.
- [MvcSiteMapNode(DynamicNodeProvider = "MyNamespace.NewsDynamicNodeProvider, MyAssembly")]
- public ActionResult News(int id)
- {
- ViewBag.id = id;
- return View();
- }
- public class NewsDynamicNodeProvider
- : DynamicNodeProviderBase
- {
- public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
- {
- using (var db = new EnityContext())
- {
- // Create a node for each news article
- foreach (var news in db.News)
- {
- var dynamicNode = new DynamicNode();
- dynamicNode.Title = news.Title;
- dynamicNode.ParentKey = "News";
- dynamicNode.RouteValues.Add("id", news.Id);
- yield return dynamicNode;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment