MVC Sitemap show only parent nodes

1.4k Views Asked by At

I want show only my parent nodes in my View. This is my sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0"           enableLocalization="true">

  <mvcSiteMapNode title="Home" controller="Home" action="Index">
    <mvcSiteMapNode title="About" controller="Home" action="About"/>
    <mvcSiteMapNode title="Contact" controller="Home" action="Contact"/>
  </mvcSiteMapNode>
  <mvcSiteMapNode title="Test" controller="Test" action="Index">
    <mvcSiteMapNode title="Teste2" controller="Test" action="Index"/>
    <mvcSiteMapNode title="Teste3" controller="Test" action="Index"/>
  </mvcSiteMapNode>  
</mvcSiteMap>

How can I use the html helper @Html.MvcSiteMap().Menu() to show only the parent nodes, and only the child nodes? Like this: Parents:

  • Home
  • Test

Childs

  • About
  • Contacts
  • Teste2
  • Teste3

Thanks.

1

There are 1 best solutions below

1
GraemeMiller On

Try for top level

@Html.MvcSiteMap().Menu(0, true, false, 1)

Second level

@Html.MvcSiteMap().Menu(2, 1, true)

This tutorial may help