maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
537 stars 220 forks source link

Support multiple top level nodes #432

Closed mwpowellhtx closed 8 years ago

mwpowellhtx commented 8 years ago

In the default Xsd there is support for just one top-level SiteMapNodeModel. I'd like to extend that to support multiple top-level nodes. There would still be the need for children, but want to have more than one top level.

At present, this seems to be as baked into the Xsd as it is in the Assembly bits, which makes it difficult to just tweak the Xsd to taste.

Thank you...

NightOwl888 commented 8 years ago

The XSD is installed into the root of your project by the MvcSiteMapProvider.Web package, so you can edit it. However, it is primarily there to support VS intellisense as editing the file would put it out of sync with the XmlSiteMapNodeProvider, which actually loads the file.

There is also an inherit limitation of a SiteMap object (which the XML ultimately populates) - it can only have one root node. But since a web site can only have a single home page, this is the most logical behavior.

It might help to know what you are attempting to achieve.

mwpowellhtx commented 8 years ago

Just my way of wrapping my way around web versus desktop, WinForms, WPF, etc.

A little off topic; is there a way to support conditional, or even forms-based, nodes? For instance, the Login/Logoff condition, support for anti-forgery tokens, etc.

NightOwl888 commented 8 years ago

You can make a node "conditional" in several ways, generally by choosing whether or not to display it.

You can make a node forms-based by changing the display templates to render a form based on whether a custom attribute is present. However, in general it doesn't make much sense to do this because a form POST does not normally represent a navigation point in the site hierarchy, those are typically GET requests.

NightOwl888 commented 8 years ago

Do note that you can hide the root node to make a SiteMapPath that doesn't display home as the default location. In the menu control, there is an option to set showStartingNode to false.

mwpowellhtx commented 8 years ago

Okay, so that's like the fourth or fifth parameter in Menu. What do you do for a startingNode or startingNodeInChildLevel? null and false? Model.First()?

@Html.MvcSiteMap().Menu("BootstrapMenuHelperModel")
mwpowellhtx commented 8 years ago

Ah, never mind. I see. It's one version of Menu() among many others. Works beautifully, thank you.