1

I have created an ASP.NET MVC5 project with vs2017 Community, and generated the controllers and views automatically via an entity, however the views are not added to the menu bar/context menu. I checked the GUIDs in the project file and they seem to be correct when matched against here. The default GUIDs from my project:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Below is the menu bar that I received

Menu bar at the top of the project

The default body code in the Shared Layout:

<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                <p class="nav navbar-text navbar-right">Hello, @User.Identity.Name!</p>
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>

How do I get the views to be added by default to the menu?

2 Answers 2

2

You need to alter this part of the code:

            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
            </ul>

to add the other menu entries that you expect to see.

If you want it more automated, check out https://www.codeproject.com/Articles/1130643/Auto-Generate-Menu-from-Controllers-in-ASP-NET-MVC or Getting All Controllers and Actions names in C# .

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I thought that this was already a default feature in this type of project.
Alas, no. You have to build it.
0

Under the <ul class="nav navbar-nav"> you should add the additional links to your views. Like below:

<li>@Html.ActionLink("Link Text", "Action Name", "Controller Name")</li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.