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 7051975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:19:41+00:00 2026-05-28T03:19:41+00:00

I’m using MVC3 (with Razor Syntax). Here’s what I’m going for: part of my

  • 0

I’m using MVC3 (with Razor Syntax).

Here’s what I’m going for: part of my shared/_Layout.cshtml which looks in the ViewBag for a List<RelatedLinks>, if it’s there it renders a list of related links in the page toolbar (unsurprisingly). Some of my pages will populate this collection, some wont. When I populate the bag from my controller it works beautifully.

However, the controller doesn’t seem like the right place for these to be defined, they’re specific to a view and they feel like navigation logic – so I’d like to define them within the view markup.

I’ve tried adding them to the ViewBag from within the view, but it doesn’t seem to work. Even if I declare a section on my _Layout.cshtml that comes before the area which renders the links, the collection appears to be empty. Either I’m doing something wrong, or they don’t allow me to fill the ViewBag from within the view (which would make sense).

What my problem boils down to is this: I want my pages to signal to the _Layout.cshtml when they want that section rendered, and provide the list of links. I don’t want my child pages to worry about how we’re populating or drawing the list – I only want it to define what’s in the list. Any ideas? I’ve tried quite a few things (HtmlHelpers, sub-classing controller, etc) but I think I’m missing something obvious.

  • 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-28T03:19:41+00:00Added an answer on May 28, 2026 at 3:19 am

    Instead of having _Layout.cshtml render the links, why not create a partial view instead?

    In _Layout, add an optional section

    @RenderSection("RelatedLinks", false)
    

    In your view,

    // Build your list of links
    @section RelatedLinks {
        @Html.Partial("Navigation", YourLinks)
    }
    

    Your views can worry about populating the list, while your partial can handle the actual rendering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MVC3 razor and in Views folder I have 4 folder: Shared _Layout.cshtml
I’m using MVC3, with the Razor syntax, and am going over an example in
I am working on an MVC3 application using the Razor syntax and I have
I am using Razor syntax in an ASP.NET MVC3 View inside a JavaScript code
I'm using MVC3 with razor view. I'm giving the user a list of <li>
I'm using mvc3 razor engine from view I call function with Uri.Action which return
I am using MVC3 (Razor) with the Paging open source code here . The
Hello all: I'm building an app using C#/MVC3/Razor which has a database configured in
I'm creating a website using MVC3, I'm using the razor syntax to create the
I am using MVC3 with Razor, for display a grid I am using a

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.