Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 194647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:36:48+00:00 2026-05-11T16:36:48+00:00

I’ve got a master page which has a function in it called GetSiteMap() ,

  • 0

I’ve got a master page which has a function in it called GetSiteMap(), this function is used to custom render a sitemap based on the current location. My problem is that in MVC you don’t have the code behind model thus not exposing that kind of functionality.

What’s the correct way to do it? Should I have a master page controller of some sort with that function defined in it?

Public Function GetSitemap() As String
    Dim s As New SiteNavigation
    Dim siteMapNodeCollection As SiteMapNodeCollection

    If Not SiteMap.CurrentNode.Equals(SiteMap.RootNode) Then
      If Not SiteMap.CurrentNode.HasChildNodes Then
        ' otherwise it'll go to the pseudo-current directory, which is wrong
        Dim parentNode As SiteMapNode = SiteMap.CurrentNode.ParentNode.ParentNode
        s.AddBackLink(parentNode.Url, parentNode.Title)
      Else
        Dim parentNode As SiteMapNode = SiteMap.CurrentNode.ParentNode
        s.AddBackLink(parentNode.Url, parentNode.Title)
      End If
    End If

    If Not SiteMap.CurrentNode.HasChildNodes Then
      siteMapNodeCollection = SiteMap.CurrentNode.ParentNode.ChildNodes
    Else
      siteMapNodeCollection = SiteMap.CurrentNode.ChildNodes
    End If

    For Each siteMapNode As SiteMapNode In siteMapNodeCollection
      GenerateLinks(siteMapNode, s)
    Next

    Return s.GetSiteNavigation()
  End Function

  Private Sub GenerateLinks(ByRef siteMapNode As SiteMapNode, ByRef siteNavigation As SiteNavigation)
    If siteMapNode.Url.Length = 0 And siteMapNode.Description = "separator" Then
      siteNavigation.AddSeparator()
    ElseIf siteMapNode.Url.Length = 0 And siteMapNode.Description = "heading" Then
      siteNavigation.AddHeading(siteMapNode.Title)
    Else
      siteNavigation.AddLink(siteMapNode.Url, siteMapNode.Description, siteMapNode.Title, siteMapNode.HasChildNodes)
    End If
  End Sub

Sorry, this is what I meant. I wrote this very quickly the other day so it’s not perfect, but for now it does the job. I’m using sitemap and giving certain elements no URL and instead a description such as “separator” to indicate that the <li> element is rendered in a different way (a different class is applied to this HTML element).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:36:48+00:00Added an answer on May 11, 2026 at 4:36 pm

    Since the site map is customizable based on the user’s location, I’m going to assume that you are talking about generating a user interface element, not a search engine mapping. Generating a sitemap for search engine consumption is probably best done off-line and simply updated periodically.

    To generate the user interface I would consider using a ViewUserControl and rendering it as a partial in whatever pages you need. The ViewUserControl will make it much easier to create and maintain the mark up associated with it. It will also be available to any view (and can be included on your MasterPage) that needs it. As @Marc Gravell suggests, the data for it can be generated using an ActionFilter. It would probably be easiest, though, if the control is ubiquitous to create a base controller from which your controllers can derive and override OnActionExecuted in the base controller. You can detect when a ViewResult has been generated, then create and assign to ViewData the data for the sitemap control.

    Base Controller:

    public override OnActionExecuted( ActionExecutedContext filterContext )
    {
         if (filterContext != null && filterContext.Result is ViewResult)
         {
             ViewData["siteMap"] = this.GetSiteMap();
         }
    }
    

    MasterPage/View

    <% Html.RenderPartial( "SiteMap", ViewData["siteMap"], ViewData ) %>
    

    ViewUserControl

     foreach (var elem in Model)
     {
        .... render your HTML
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 141k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For flickr you can use flickr_fu or flickr. You should… May 12, 2026 at 8:08 am
  • Editorial Team
    Editorial Team added an answer Here's a simplified version of how I do this: XtraReport… May 12, 2026 at 8:08 am
  • Editorial Team
    Editorial Team added an answer You should look into ZeroConf as a generic way of… May 12, 2026 at 8:08 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.