Bootstrap在Razor Pages中不起作用 [英] Bootstrap not working in Razor Pages
问题描述
Bootstrap正在我的索引页面中工作,并且默认情况下会生成其他页面....但是我在页面内部创建的文件夹和在这些页面上使用crud的脚手架无法工作.....我尝试了同样的事情在asp.net core 2 mvc模板中,它可以正常工作.
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.
这是我的创建视图
@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>
推荐答案
您没有刷新< head>
中的Bootstrap,因此页面无法知道您要加载它.
You're not refreshing Bootstrap in your <head>
so the page has no way of knowing you want to load it.
您需要遵循以下条件:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
由于它可以在其他页面上使用,因此我假设您已从 _Layout.cshtml
(或其他共享布局)引用了该库.但是,将不会使用此布局,因为您已明确告诉它 not 来加载布局:
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;
}
这篇关于Bootstrap在Razor Pages中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!