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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:54:05+00:00 2026-05-29T07:54:05+00:00

I wanted use MVC and renderpartial to generate a menu but but could not

  • 0

I wanted use MVC and renderpartial to generate a menu but but could not get it to work, and from what I read it seemed maybe RenderAction would be more suitable. Still I have not gotten it to work.

What I intended to do was create a controller that selects certain articles from a database that will act as categories (this is put into HomeController):

public ActionResult MenuController()
    {
        var movies = from m in db.Art
                     where m.ArtikelNr.StartsWith("Webcat")
                     select m;
        return View(movies);
    }

And then send that information to a view:

@model IEnumerable<xxxx.Models.Art>
@{
Layout = null;
}

<ul>
@foreach (var item in Model)
{
<li>@Html.DisplayFor(modelItem => item.Benämning_10)</li>
}

This works when I just run it as a normal controller and view, it returns a list of what I want. But if I want to call it from _layout.cshtml (because this menu should appear on every page) like this:

<div id="sidebar">@Html.RenderAction(MenuController)</div>

Then it generates the following error:

CS0103: The name 'MenuController' does not exist in the current context

What is the proper way of calling an action/view/whatever from the _layout.cshtml file?

  • 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-29T07:54:06+00:00Added an answer on May 29, 2026 at 7:54 am

    You should call

    @Html.RenderAction("_MenuController")
    

    and be sure that you have a working rule in your Global.asax

    As suggested in another answer would be better to use

    return PartialView();
    

    I also suggest you to use the ChildActionOnlyAttribute to be sure that this action will never be called as a standard action.

    So something like that:

    [ChildActionOnly]
    public PartialViewResult _MenuController()
    {
        var movies = from m in db.Art
                     where m.ArtikelNr.StartsWith("Webcat")
                     select m;
        return PartialView(movies);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to use boost::thread in my program, but get the following compiler error
I wanted to use T4 to generate properties for a partial class. I'm running
I wanted to use one of the Git-completion.bash features but I can't customize the
I wanted to use JET (Java Emitter Templates) in my Netbeans projects, but had
I wanted to use monotouch, but unfortunately I don't have $400 to spend. So
I am currently learning the zsh and now I wanted to use strftime but
I have already designed about 3 templates I wanted to make use of, but
I am trying to use the MVC design. In the model I wanted a
I wanted to use Spring MVC hidden tag in below code. Is this possible
I wanted to get your opinion about managing scripts in ASP .NET MVC. There

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.