4

I created a project that the nodes are defined using attributes, and I set it in the web.config to scan for attributes, and it works fine.
I don't use an XML file at all.

Now I want to add a dynamic node provider, how do I do it?
Is there a way to do it without the XML (.sitemap) file?
I need to make sure it's under the root, which has been set in code using MvcSiteMapNodeAttribute attribute.

I've read the documentation and I can't really figure out where to place this line:

<mvcSiteMapNode
  title="Details" action="Details"              
  dynamicNodeProvider="Project.StoreDetailsDynamicNodeProvider, Prject" />

What action is it supposed to point to? Additionally as said above, the root element is defined using attributes, so my question is if there is a way to avoid XML, or alternatively what's the efficient way to declare the XML (the less the better) to include my dynamic provider.

Update

I've tried the following and the node provider still isn't reached (From HomeController.cs).

[MvcSiteMapNode(Title = "Home", Key = HomeMenuKey,
  DynamicNodeProvider = "Project.Namespace.NodeProvider, Assembly")]
public ActionResult Index()
{
  return View();
}
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
  • Have you followed the documentation as detailed [here](https://github.com/maartenba/MvcSiteMapProvider/wiki/Dynamic-sitemaps)? – Mightymuke Nov 16 '12 at 13:20
  • @Mightymuke I've read that before. question updated. – Shimmy Weitzhandler Nov 16 '12 at 13:25
  • Take a look at this (semi related) question - it might give some pointers: http://stackoverflow.com/questions/6169694/mvc-sitemapprovider-nullreferenceexception-after-refreshing-dynamic-node-pag – Mightymuke Nov 16 '12 at 13:35
  • Sorry that the above comments aren't that great (its 3am here). I've had a quick look around and it doesn't appear that you can do it without a sitemap node in an XML file as it provides both the node template AND the reference to the dynamic node provider. However I've never used dynamic nodes before, so could very well be wrong. – Mightymuke Nov 16 '12 at 14:18
  • @Mightymuke, I said I don't mind using the XML. The problem is root menu (and the other menus) are all defined in attributes, and so I don't know what to write in the XML file. – Shimmy Weitzhandler Nov 19 '12 at 07:32

2 Answers2

2

Can you define it in the controller method attributes (and not use XML at all)?

For example:

[MvcSiteMapNode(Title="Details", 
  DynamicNodeProvider = "Project.StoreDetailsDynamicNodeProvider, Project")]
public ActionResult Index()
{
    return View();
}
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
Mightymuke
  • 5,094
  • 2
  • 31
  • 42
  • It doesn't work. Am I missing something? What controller should I place that attribute at? Can you explain how it's supposed to work? Am I missing something? I've added an example to my question, please check it out. Thanks – Shimmy Weitzhandler Nov 22 '12 at 19:57
  • I've never used `DynamicNodeProvider` before, but I'll take a look shortly and see if I can get it working with your setup. – Mightymuke Nov 22 '12 at 20:20
  • Bounty awarded for your effort, and for finding the `DynamicNodeProvider` property in the `MvcSiteMapNodeAttribute`. I wasn't aware of that. – Shimmy Weitzhandler Nov 22 '12 at 23:06
1
  1. Seems that the dynamicNodeProvider attribute is ignored in the root node, also when it's defined in attributes.
    So the only way to add a dynamic node provider under the root, is either by specifying it on a dummy action etc. or using XML.
  2. An interesting note: the actual difference between defining in XML and attributes is that if it's defined in attributes, it (i.e. the gen. menu items) will be last in the menu, whereas when defined in XML it will be right after the root item (I guess that would be Home), Note that this is still controllable via the Order property in the attributes.
  3. In my Web.Config, I left the siteMapFile empty, relying in what it said in the wiki page, that the default value is ~/Web.sitemap, in fact this is false (I've already corrected that in the updated wiki).
    I don't think this behavior should be like this, I do think the MvcSiteMap engine should scan for dynamic node providers just as it scans for dynamic node attributes (here is the issue I posted on site).
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632