【问题标题】:Bootstrap template is not working in MVC application引导模板在 MVC 应用程序中不起作用
【发布时间】:2018-06-07 06:22:19
【问题描述】:

我正在尝试使用来自https://bootswatch.com/superhero/Bootstrap 的免费Bootstrap template Bootstrap。我从这个站点复制了bootstrap.cssbootstrap.min.css 并粘贴到我的应用程序中,但我的应用程序没有像这个模板那样显示navbar。 请从本网站和我的主页中找到随附的屏幕截图。

来自这个网站:

来自我的申请:

我的_Layout.cs

<!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>&copy; @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 class BundleConfig
    {
        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        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*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://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/bootstrap").Include(
    "~/Content/bootstrap.css",
    "~/Content/bootstrap-theme.css"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }
    }

非常感谢任何建议。谢谢。

【问题讨论】:

标签: css asp.net-mvc twitter-bootstrap


【解决方案1】:

您可能使用的 Bootstrap 版本与用于 Bootswatch 主题的版本不同。我遇到了同样的问题,并在 Github 上打开了一个问题,Thomas Park 给了我以下答案:

是的,只要确保您使用的版本与所使用的 Bootstrap 相同。目前 v4 在 bootswatch.com 上,但您可以通过 https://bootswatch.com/3/https://bootswatch.com/2/ 获取旧版本

因此,请尝试使用您想要的旧版 Bootswatch 主题(来自上面的链接)更新您的 Bootstrap 版本

来源:https://github.com/thomaspark/bootswatch/issues/784

【讨论】:

    【解决方案2】:

    在我的 _Layout.cshtml 文件中,我在头部给出了这样的脚本和样式:

    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/Custom")
    </head>

    在您的 Bundle Config 文件中,我认为您不需要两个单独的语句来包含相同的 bootstrap.css 文件。

    【讨论】:

      【解决方案3】:

      不要使用 bundles.config 和渲染脚本。只需下载 bootstrap.min.css 文件并将其复制到 MVC 项目中的文件夹之一。在 _layout.cshtml 文件中,将该 css 文件拖放到标签内。它必须工作。试试看。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-12
        • 2014-11-20
        • 2019-02-25
        • 1970-01-01
        相关资源
        最近更新 更多