【问题标题】:bootstrap works locally but not when deployedbootstrap 在本地工作,但在部署时不工作
【发布时间】:2014-04-02 03:09:53
【问题描述】:

我正在使用 MVC 框架和引导程序来优化网站。一切都在本地工作,但不在服务器上。该网站没有css watsoever。此外,首页应该是一个轮播滑块,现在它只是以垂直方式显示的所有图片。有什么问题?

这是我的代码:

@using System.Web.Optimization;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - The Secured Password</title>
@Scripts.Render("~/bundles/bootstrap")
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@*@Scripts.Render("~/bundles/jqueryval")*@
@RenderSection("scripts", required: false)
</head>
<body>
<div class="navbar-wrapper">
    <div class="container">

谢谢!

已编辑:

这是渲染的标题:

<link href="/Content/css?v=UV-jZ4aDFGX-mj3fDEnMFNwudw9kdbZQj1zFCxtmgps1"   rel="stylesheet">

<script src="/bundles/modernizr?v=wBEWDufH_8Md-Pbioxomt90vm6tJN2Pyy9u9zHtWsPo1">   </script><style type="text/css"></style>

<script src="/bundles/jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1"></script>

<script src="/bundles/bootstrap?v=HHeOtfpYTGpvkQWzPsmQOp39ZdG4zLSAsANOtnmyV-g1"></script>

编辑#2: 这是 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(
                    "~/Content/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Content/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(
                    "~/Content/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Content/Scripts/bootstrap.js",
                  "~/Content/CSS/respond.js"));

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

【问题讨论】:

  • 你使用的是哪个框架?
  • 能否也给我们展示一下渲染后的标头代码?
  • 我正在使用 MVC 框架
  • 仅供参考,MVCModel/View/Controller 的首字母缩写。您正在使用 ASP.NET MVC 框架。
  • 经验教训,谢谢菲尔!

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


【解决方案1】:

没有任何东西可以渲染 Bootstrap 自己的 css 文件(bootstrap[.min].css 和 bootstrap-theme[.min].css)。

【讨论】:

  • 那我该如何解决呢?我确定这些文件在服务器上,只是没有渲染它。
  • 检查您的Content 文件夹的内容(呵呵)。那里似乎有些混乱,因为您的&lt;link&gt; 渲染不正确。这两个文件以及您(或 Visual Studio)创建的任何 CSS 都应该在其中。看看你是否可以从asp.net/mvc/tutorials/mvc-5/introduction 成功运行“电影”应用程序,它使用了 Bootstrap。
【解决方案2】:

现在解决了。我只是更改了cshtml代码:

@Scripts.Render("~/bundles/bootstrap")
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")

部分是普通的html代码

<script src="/bundles/bootstrap.css"></script>

解决方案不多,但它解决了我的问题。

感谢大家的帮助。

【讨论】:

  • 如果您更改应用的位置(例如将其放在子目录中),这将不起作用
【解决方案3】:

bootstrap.css 是否包含在您的“~/Content/css”包中?检查您的 BundleConfig.cs RegisterStyleBundles 函数以查看您是否已在该捆绑包中正确包含引导 css,因为您没有呈现任何其他样式捆绑包,如果它未正确包含在该捆绑包中,那么这肯定会解释为什么您没有得到 css。

【讨论】:

  • 感谢您的回复,但我检查了 BundleConfig,他们在里面。
  • 但这并不能告诉我们您包含它的方式是否有问题。您能否向我们展示您的 BundleConfig.cs?
猜你喜欢
  • 2021-05-22
  • 2012-08-21
  • 2020-09-24
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多