Bootstrap not working in Razor Pages

三世轮回 提交于 2021-02-10 05:16:06

问题


Bootstrap is working in my index page and other pages which are by default generate....But the folder i create inside pages and scaffold using crud on those pages bootstrap is not working.....I tried the same thing in asp.net core 2 mvc template and it works fine.

Here is my create view

@page
@model Memberships.Pages.Section_Page.CreateModel

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Create</title>
</head>
<body>

<h4>Section</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form method="post">
            <div asp-validation-summary="ModelOnly" class="text-danger">
</div>
            <div class="form-group">
                <label asp-for="Section.Title" class="control-label">
</label>
                <input asp-for="Section.Title" class="form-control" />
                <span asp-validation-for="Section.Title" class="text-
danger"></span>
            </div>
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" class="btn btn-
success" />
                </div>
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-page="Index">Back to List</a>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
</body>
</html>


回答1:


You're not refreshing Bootstrap in your <head> so the page has no way of knowing you want to load it.

You need something along the lines of:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">

Since it is working on other pages, I assume you've referenced the library from your _Layout.cshtml (or some other shared layout). This layout won't be used however because you've explicitly told it not to load a layout:

@{
   Layout = null;
}


来源:https://stackoverflow.com/questions/48508129/bootstrap-not-working-in-razor-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!