问题描述
我们更新了所有NuGet软件包后,一个MVC应用程序中断了.尝试一切之后,我创建了一个新的MVC应用程序,更新了NuGet软件包和基本的导航栏...
An MVC app broke after we updated all the NuGet packages. After trying everything I created a new MVC app, updated the NuGet packages and the basic navbar...
<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>
<a class="navbar-brand" href="/">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/Home/About">About</a></li>
<li><a href="/Home/Contact">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/Account/Register" id="registerLink">Register</a></li>
<li><a href="/Account/Login" id="loginLink">Log in</a></li>
</ul>
</div>
</div>
</div>
...看起来像这样...
... looks like this ...
...然后单击图标...
...and clicking the icon...
有什么想法会导致这种情况吗?
Any ideas what could be causing this?
尝试将Bootstrap.css和Bootstrap.js手动添加到_Layout.vbhtml中,但没有区别
Have tried manually adding Bootstrap.css and Bootstrap.js to _Layout.vbhtml, but no difference
谢谢
推荐答案
最后,我管理了HTML和您的HTML.与版本3相比,Bootstrap 4有很多更改.关于标记,您必须进行以下更改:
Finally, I managed my HTML and yours.There're a lot of changes in Bootstrap 4 in compare to version 3. Regarding your markup, you have to change:
- 将"Navbar-inverse"改为"Navbar-dark",并使用颜色"bg-dark".
- 为按钮添加一些属性,例如"aria-controls","aria-expanded","aria-label"和"data-target",以链接到另一个元素.
- 可折叠元素的属性"id".
- 对于列表元素(标签LI),应添加class ="nav-item"
- 对于链接之外的列表元素,请添加class ="nav-link".
- 我建议在"definiton"列表中添加"mr-auto".
下面的所有更改.在此处进行了测试.
All changes below. Tested here.
<nav class="navbar navbar-expand-sm navbar-dark fixed-top bg-dark">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
</button>
<a class="navbar-brand" href="/">Application name</a>
<div class="navbar-collapse collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav mr-auto">
<li class="nav-item"><a href="/" class="nav-link">Home</a></li>
<li class="nav-item"><a href="/Home/About" class="nav-link">About</a></li>
<li class="nav-item"><a href="/Home/Contact" class="nav-link">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right mr-auto">
<li class="nav-item"><a href="/Account/Register" id="registerLink" class="nav-link">Register</a></li>
<li class="nav-item"><a href="/Account/Login" id="loginLink" class="nav-link">Log in</a></li>
</ul>
</div>
</div>
</nav>
这篇关于运行NuGet更新后MVC引导导航栏不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!