简体   繁体   中英

Connecting Bootstrap to ASP.NET _Layout.cshtml file

I'm following an older book (2017) so the code is outdated

I'm having a problem connecting bootstrap to _Layout.cshtml

I believe the problem is this link to bootstrap

<link rel="stylesheet" asp-href-include="/lib/bootstrap/dist/**/*.min.css"
      asp-href-exclude="**/*-reboot*,**/*-grid" />

Since there is no wwwroot folder anymore. How do I link bootstrap correctly?

Here is my _Layout.cshtml code:

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" asp-href-include="/lib/bootstrap/dist/**/*.min.css"
          asp-href-exclude="**/*-reboot*,**/*-grid" />
    <title>SportsStore</title>
</head>
<body>
    <div class="navbar navbar-inverse bg-inverse" role="navigation">
        <a class="navbar-brand"
           href="#">SPORTS STORE</a>
    </div>
    <div class="row m-1 p-1">
        <div id="categories" class="col-3">
            Put something useful here later.
    </div>
    <div class="col-9">
        @RenderBody()
    </div>
        </div>
</body>
</html>

Here is my solution explorer image

Here is the List.cshtml that I'm trying to use bootstrap with

@model ProductsListViewModel

@foreach (var p in Model.Products)
{
    <div class="card card-outline-primary m-1 p-1">
        <div class="bg-faded p-1">

            <h4>
                @p.Name
                    <span class="badge badge-pill badge-primary" style="float:right">
                        <small>@p.Price.ToString("")</small>
                    </span>
                </h4>
        </div>

        <div class="card-text p-1">@p.Description</div>
    </div>
}

<div page-model="@Model.PagingInfo" page-action="List" page-classes-enabled="true"
    page-class="btn" page-class-normal="btn-secondary"
    page-class-selected="btn-primary" class="btn-group pull-right m-1">

</div>

You can use CDN links.

You should link the css library in the head tag , and scripts to last of body tag .

<head>
    .....
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

<body>
    ......

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>

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