Bootstrap 4无法在Razor View中渲染

问题描述 投票:0回答:1

我已经从Bootstrap 3更新到Bootstrap 4,现在Razor View无法正常渲染,如下图所示:

enter image description here

正如您所看到的,所有Bootstrap样式都消失了,导航栏已经消失。 Bootstrap 3很好用。

这只是MVC项目附带的标准登录页面,所以我没有添加任何花哨的东西。

我的包如下:

using System.Web;
using System.Web.Optimization;

namespace FoodSnap
{
public class BundleConfig
{
    // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                   "~/Scripts/jquery-{version}.js",
                   "~/Scripts/jquery-ui-{version}.js"));

        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",
            "~/Content/themes/base/jquery-ui.css"));
    }       

}

}

在我看来,我已呈现如下:

<!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("FoodSnap_TEST", "LogIn", "Account", 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>*@
                <li>@Html.ActionLink("Pre-Registration", "Index", "PreRegistration")</li>
                <li>@Html.ActionLink("Roles", "Index", "Role")</li>
                <li>@Html.ActionLink("FoodSnap", "Index", "FoodSnap")</li>
                <li>@Html.ActionLink("Review", "Create", "FoodSnap")</li>
            </ul>
            @Html.Partial("_LoginPartial")
        </div>
    </div>
</div>
<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - FoodSnap_TEST</p>
    </footer>
</div>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

我尝试了很多东西,包括CDN,结果是一样的。谁看过这个吗?

asp.net-mvc razor bootstrap-4
1个回答
1
投票

Bootstrap 4几乎完全重写了Bootstrap 3,这意味着:

Bootstrap 3代码均未与Bootstrap 4兼容。

阅读要迁移的文档:

https://getbootstrap.com/docs/4.0/migration/

© www.soinside.com 2019 - 2024. All rights reserved.