Reputation: 855
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
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>© @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?
Upvotes: 1
Views: 763
Reputation: 53958
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>
Upvotes: 0
Reputation: 23956
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# .
Upvotes: 2