Jack Zach Tibbles
Jack Zach Tibbles

Reputation: 800

How to retrieve level/depth of current MvcSiteMap node?

I need to find out what level of the menu my current page is on.

I have access to the current node object using razor syntax within my HTML page:

@Html.MvcSiteMap().SiteMap.CurrentNode

Is there a property/method that can show the current nodes depth/level within the sitemap or do I need to write something to traverse the sitemap xml?

Upvotes: 1

Views: 542

Answers (1)

ramiramilu
ramiramilu

Reputation: 17182

You need to use SiteMapPath() to get the breadcrumb menu -

@Html.MvcSiteMap().SiteMapPath()

Output would be shown like this -

enter image description here

Reference taken from here.

EDIT -

Can you try like this in View -

var depthCount = Html.MvcSiteMap().SiteMap.CurrentNode;
@depthCount.Ancestors.Count + 1 // will give you depth count

Upvotes: 2

Related Questions