Guest User

Untitled

a guest
Jan 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. //Controller Name=News
  2.  
  3. Home
  4. News
  5. first //id=1
  6. second //id=2
  7. third // id=3
  8. About
  9.  
  10.  
  11. <mvcSiteMapNode title="Home" controller="Home" action="Index">
  12. <mvcSiteMapNode title="News" controller="News" action="Index" key="News">
  13. </mvcSiteMapNode>
  14. <mvcSiteMapNode title="About" controller="About" action="Index"/>
  15.  
  16. [MvcSiteMapNode(Title = "News", ParentKey = "News")]
  17. public ActionResult News(int id)
  18. {
  19. ViewBag.id = id;
  20. return View();
  21. }
  22.  
  23. <mvcSiteMapNode title="News" controller="News" action="News" preservedRouteParameters="id"/>
  24.  
  25. [MvcSiteMapNode(Title = "News", ParentKey = "News", PreservedRouteParameters = "id")]
  26. public ActionResult News(int id)
  27. {
  28. ViewBag.id = id;
  29. return View();
  30. }
  31.  
  32. <mvcSiteMapNode title="Article 1" controller="News" action="News" id="1"/>
  33. <mvcSiteMapNode title="Article 2" controller="News" action="News" id="2"/>
  34. <mvcSiteMapNode title="Article 3" controller="News" action="News" id="3"/>
  35.  
  36. [MvcSiteMapNode(Title = "Article 1", ParentKey = "News", Attributes = @"{ ""id"": 1 }")]
  37. [MvcSiteMapNode(Title = "Article 2", ParentKey = "News", Attributes = @"{ ""id"": 2 }")]
  38. [MvcSiteMapNode(Title = "Article 3", ParentKey = "News", Attributes = @"{ ""id"": 3 }")]
  39. public ActionResult News(int id)
  40. {
  41. ViewBag.id = id;
  42. return View();
  43. }
  44.  
  45. <mvcSiteMapNode title="News" controller="News" action="Index" key="News">
  46. // Setup definition node in XML (won't be in the SiteMap)
  47. // Any attributes you put here will be the defaults in the dynamic node provider, but can be overridden there.
  48. <mvcSiteMapNode dynamicNodeProvider="MyNamespace.NewsDynamicNodeProvider, MyAssembly" controller="News" action="News"/>
  49. </mvcSiteMapNode>
  50.  
  51. // Setup definition node as a .NET Attribute (won't be in the SiteMap)
  52. // Any properties you put here will be the defaults in the dynamic node provider, but can be overridden there.
  53. [MvcSiteMapNode(DynamicNodeProvider = "MyNamespace.NewsDynamicNodeProvider, MyAssembly")]
  54. public ActionResult News(int id)
  55. {
  56. ViewBag.id = id;
  57. return View();
  58. }
  59.  
  60. public class NewsDynamicNodeProvider
  61. : DynamicNodeProviderBase
  62. {
  63. public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
  64. {
  65. using (var db = new EnityContext())
  66. {
  67. // Create a node for each news article
  68. foreach (var news in db.News)
  69. {
  70. var dynamicNode = new DynamicNode();
  71. dynamicNode.Title = news.Title;
  72. dynamicNode.ParentKey = "News";
  73. dynamicNode.RouteValues.Add("id", news.Id);
  74.  
  75. yield return dynamicNode;
  76. }
  77. }
  78. }
  79. }
Add Comment
Please, Sign In to add comment