我正在使用 Visual Studio 2019,并遵循 ASP.NET MVC 教程,其中从 bootswatch 下载 bootstrap.css 文件,然后将其放置在 MVC Web 应用程序的 Content 文件夹中。转到 BundleConfig.cs 并将引导文件的名称从 bootstrap.css 更改为 bootstrap-lumen.css 后,新页面应该可以完美呈现,但由于某种原因,导航栏没有出现在我的页面上。
我已经尝试过 Bootswatch 中的其他 css 文件,例如:
在这两种情况下,按钮都会根据新主题进行更改,但导航栏会损坏,我不知道为什么。我完全按照教程中的讲师所做的操作:
这是我的 _Layout.cshtml 文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<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>
@Html.Partial("_LoginPartial")
</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>
</html>
感谢大家的帮助。我通过切换到 Visual Studio 2022 并使用 Visual Studio 下载器安装更多用于 mvc Web 开发的扩展解决了这个问题。