首先,非常感谢您专心阅读问题!
我告诉你,前段时间我正在使用 ASP.NET MVC 5 做一个项目,结果从一天到下一天,打开它时,_Layout.cshtml 的样式完全崩溃了(没有做任何更改大约 10 天前)
我回到了 Visual Studio 自动生成的 _Layout.cshtml,问题仍然存在。
_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>
</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>
默认情况下我也有捆绑包
BundleConfig.cs
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Utilice la versión de desarrollo de Modernizr para desarrollar y obtener información. De este modo, estará
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
应该注意的是,前一段时间我更新到 Bootstrap 4.0,但是,我更新了,一切都继续正常工作,直到现在,10 天后,一切都爆炸了
在浏览器控制台中没有任何库的读取问题错误,但是,我留下了一个图像,以便您可以欣赏编译时生成的内容。
在图像中,导航栏出现故障,“了解更多”按钮和字体发生了重要变化
什么时候应该输出如下。
伙计们,首先非常感谢你们,我希望有人知道为什么会这样!
干杯!
发生这种情况是因为 ASP.NET MVC 的默认模板与 Bootstrap 4 不兼容,我已尝试更改您的模板以与 Bootstrap 4 一起使用,请记住该库具有以下依赖项:
我已经改变
@Render
了你的观点,因为 .NET Fiddle 不接受这些方法,事不宜迟,我把对我有用的留给你:发生这种情况是因为许多类的名称(Like
navbar-fixed-top
)被更改以更好地使用,就像生成链接的方式也发生变化一样,您必须向它们添加一个类nav-link
,以便它们显示为navbar
,在这里,我让您了解一下我是如何使用默认出现在Bootstrap页面上的模板来实现它的。同样的,如果你通过 Bootstrap 4 的入门,你可以看到
meta
使用 Bootstrap 4 需要哪些标签和依赖项。最后,向你的集合添加一个新的是一个好主意
ScriptBundle
,这样你只需要修改你视图中的 CSS 类的名称:我没有很好地使用
ScriptBundle
,但是在制作@Scripts.Render("~/bundles/popper")
和离开您的 Bootstrap 4 就绪模板时它应该可以工作。