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

  • SEARCH
  • Home
  • 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 6646305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:24:01+00:00 2026-05-26T00:24:01+00:00

I have a _layout.cshtml containing this row: @{Html.RenderPartial(Menu);} Now I want to pass in

  • 0

I have a _layout.cshtml containing this row:

@{Html.RenderPartial("Menu");}

Now I want to pass in a model into this RenderPartial-function. This model can be read from my repository.

How and where(in code) can this be done?

Thanks!

  • 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-26T00:24:02+00:00Added an answer on May 26, 2026 at 12:24 am

    RenderPartial has an overload that can take an object to send it to the partial view.
    Don’t forget to define your @model at the top of your partialview to work with the right object type.

    @Html.RenderPartial(“ViewName”,object)

    Extra info: MSDN

    Edit after comment:

    I think it would be easier to create a MenuController that takes in the repository. Then let it create a view which takes in the required repository as it’s model, then with a foreach render every menu-item as actionlinks, passing the menu info to it.

    So you would have this in your _layout.cshtml:

    <div id="Menu">
        @{Html.RenderAction("Menu", "Menu");}
    </div>
    

    This in your MenuController:

    public class MenuController : Controller
    {
        private IMenuRepository _repository;
    
        public MenuController(IMenuRepository repo)
        {
            _repository = repo;
        }
        //
        // GET: /Menu/
    
        public PartialViewResult Menu(string menu = null)
        {
            ViewBag.SelectedMenu = menu;
    
            IEnumerable<MenuInfoObject> menus= _repository.Menus;
            return PartialView(menus);
        }
    }
    

    And your MenuView:

        @model IEnumerable<MenuInfoObject>
    @{
        Layout = null;
    }
    @foreach (var item in Model)
    {
        @Html.RouteLink(item.MenuName, new
    {
        controller = item.ControllerInfo,
        action = item.ActionInfo,
    }, new
           {
               @class = item.Menu == ViewBag.SelectedMenu ? "selected" : null
           })
    }
    

    Would that be any closer to a solution?

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

Sidebar

Related Questions

I have something like @{ Html.RenderPartial(@~/Views/Management/_Main.cshtml); } Can I change this view without page
I have an Index.cshtml view: @model AttendenceModel @{ Layout = ~/Views/Shared/_Layout.cshtml; } @using (Html.BeginForm(VisOppsummering,
in my _Layout.cshtml file I have @Html.Partial(_SearchPartial) In this partial file I have @using
I have created a mvc 3 web app. _Layout.cshtml contain following menu <li>@Html.ActionLink(Contact Us,
I have a top-level _Layout.cshtml that looks something like this: <html> <head> @RenderSection(Header, required:
I created an asp mvc3 project, I want to have a different _Layout.cshtml depending
i have a master page called layout.cshtml and a page called testpage.cshtml. On this
I have following code snipped in _Layout.cshtml <div id=sub-navig-container> @RenderSection(subNavig) </div> <div id=text-content> @RenderBody()
I have a base layout, BaseLayout.cshtml: <html> <body> @RenderBody() <div id=footer> @if (!IsSectionDefined(Footer)) {
I am using an mvc application and in _Layout.cshtml page I have some javascript

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.