簡體   English   中英

Bootstrap不能與ASP.net MVC Bundling一起使用

[英]Bootstrap not working with ASP.net MVC Bundling

我正在使用bootstrap在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

我在視圖文件夾下的共享目錄中使用了bundling和_Layout.cshtml。

有人可以幫助解決這個問題嗎?

注意 :我沒有粘貼模型和控制器的代碼,因為我認為這里不需要它。

謝謝。

protected virtual void Application_Start()
    {
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

這是缺失的。 搞定了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM