I am learning the basis of HTML, Bootstrap & JavaScript. I want to use bootstrap nav class for navigation. The first problem: bootstrap doesn’t work in shared view _Layout.cshtml
and buttons look like:
But the content of index.cshtml
looks OK.
The second problem: when I click on Messages, it redirects me only to controller ../User, not to its action ../User/Index. I have no idea why it does not work.
Below my _Layout.cshtml
code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/lib/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
<script src="~/lib/twitter-bootstrap/js/bootstrap.js"></script>
<title>@ViewData["Title"] - title</title>
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<ul class="nav nav-tabs">
<li role="navigation" class="active"><a href="#">Home</a></li>
<li role="navigation"><a href="#">Profile</a></li>
<li role="navigation"><a href="@Url.Action("Index", "User")">Messages</a></li>
</ul>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false)
</body>
</html>
2
Answers
Everything works fine when I manually go to ../User/Index view. Here is the part of
UserController.cs
class:For first problem, Try to change from
To:
For second problem, try to change from
@Url.Action("Index", "User")
to@Url.Action("User")
You have to make sure that your controller naming is correct. Otherwise, we may need your UserController sample code for further assist