Bootstrap does not work with ASP.net MVC Bundling

I am creating a simple ASP.net MVC login page with loading

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>

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

When the project starts, the controls are displayed, but the boot classes are not applied to the controls.

In the browser console, I get 404 error for packages:

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

I used bundling and _Layout.cshtml in the public folder in the view folder.

Can someone help with this problem?

Note . I did not insert the model and controller code, because I think that it is not needed here.

Thank.

+4
source share
1 answer
protected virtual void Application_Start()
    {
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

It was absent. It worked.

+2

Source: https://habr.com/ru/post/1681465/


All Articles