【问题标题】:Bootstrap not working with ASP.net MVC BundlingBootstrap 不适用于 ASP.net MVC 捆绑
【发布时间】:2017-12-19 17:30:56
【问题描述】:

我正在使用引导程序在 ASP.net MVC 中创建一个简单的登录页面

BundleConfig.cs

public class BundleConfig
    {

        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.IgnoreList.Clear();

            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-1.9.1.js"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrapjs").Include(
                        "~/Scripts/bootstrap.min.js"));

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

_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/bootstrapcss")
</head>
<body>
    @RenderBody()
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrapjs")
</body>
</html>

查看:Index.cshtml

@model ME.Models.Admin.AdminModel

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/shared/_Layout.cshtml";
}

<center>
<div class="panel panel-primary" style="display:inline-block">
    Hello Admin! Please Login
    <br />

    <table>
        <tr>
            <td>@Html.LabelFor(m=>m.username)</td>
            <td>@Html.TextBoxFor(m=>m.username, new { @class = "form-control" })<br /></td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m=>m.password)</td>
            <td>@Html.TextBoxFor(m=>m.password, new { @class = "form-control" })<br /></td>

        </tr>
        <tr>
            <td></td>
            <td><input type="submit" class="btn btn-primary" value="Log In" /></td>
        </tr>
    </table>

</div>
    </center>

在运行项目时,会显示控件,但不会将引导类应用于控件。

在浏览器控制台下我收到捆绑包的 404 错误:

/bundles/jquery
/bundles/bootstrapjs
/Content/bootstrapcss

我在视图文件夹下的共享目录中使用了捆绑和_Layout.cshtml。

有人可以帮忙解决这个问题吗?

注意:我没有粘贴模型和控制器的代码,因为我认为这里不需要。

谢谢。

【问题讨论】:

  • 浏览器是否加载捆绑包或是否有任何错误?为什么你既是缩小版又是普通的引导 css?
  • 在创建新包之前尝试添加BundleTable.EnableOptimizations = true;
  • @BobSwager 我必须在 BundleConfig 类中添加这个吗??
  • 是的。但我认为您的解决方案应该是这样的:stackoverflow.com/questions/13458642/…
  • @All。我收到 /bundles/jquery、/bundles/bootstrapjs /Content/bootstrapcss 的 404 错误。我必须创建捆绑目录吗??

标签: c# asp.net .net twitter-bootstrap asp.net-mvc-4


【解决方案1】:
protected virtual void Application_Start()
    {
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

这是丢失的。搞定了。

【讨论】:

    猜你喜欢
    • 2018-09-02
    • 1970-01-01
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    相关资源
    最近更新 更多