简体   繁体   中英

bootstrap works locally but not when deployed

I'm using MVC framework and bootstrap to optimize the website. Everything works locally but not on the server. The website has no css watsoever. Also the front page should be a carousel slider and now it's just all the pictures displayed in a vertical manner. What is the problem?

Here is my code:

@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">

Thanks!

EDITED:

Here is the rendered header:

<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>

Edited #2: Here is the content for 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"));
    }
}

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

Now it's fixed. I simply changed the cshtml code:

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

part to be normal html code as

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

Not much a solution but it solved my problem.

Thank you all for the help.

Is bootstrap.css included in your "~/Content/css" bundle? Check your BundleConfig.cs RegisterStyleBundles function to see if you've properly included the bootstrap css in that bundle, since you aren't rendering any other style bundles, if it isn't included in that bundle properly then that would certainly explain why you weren't getting the css.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM