【问题标题】:Bootstrap not working in Razor Pages引导程序在 Razor 页面中不起作用
【发布时间】:2018-01-29 18:55:42
【问题描述】:

Bootstrap 正在我的索引页面和默认生成的其他页面中工作....但是我在这些页面上使用 crud 创建的文件夹和脚手架 bootstrap 不起作用.....我尝试了同样的事情在 asp.net core 2 mvc 模板中,它工作正常。

这是我的创建视图

@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>

【问题讨论】:

  • 具体是什么不起作用?

标签: twitter-bootstrap razor asp.net-core-2.0


【解决方案1】:

您没有在 &lt;head&gt; 中刷新 Bootstrap,因此该页面无法知道您要加载它。

你需要一些类似的东西:

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

由于它在其他页面上工作,我假设您已经从您的 _Layout.cshtml(或其他一些共享布局)中引用了该库。但是,不会使用此布局,因为您已明确告诉它不要加载布局:

@{
   Layout = null;
}

【讨论】:

  • 他为什么要把is layout设置为null?
猜你喜欢
  • 2021-02-13
  • 2013-05-23
  • 1970-01-01
  • 2021-01-17
  • 1970-01-01
  • 2021-01-03
  • 2019-08-15
  • 1970-01-01
  • 2019-12-16
相关资源
最近更新 更多