在 MasterPage (ASPX) 中定义ContentPlaceHolder或在布局页面 (Razor) 中定义Section
ASPX:
<body>
<!-- End of Body -->
<asp:ContentPlaceHolder ID="JavaScriptIncludes" runat="server" />
</body>
剃须刀:
<body>
<!-- End of Body -->
@RenderSection("JavaScriptIncludes", required: false)
</body>
然后在部分:
ASPX:
<asp:Content ID="ExtraJs" ContentPlaceHolderID="JavaScriptIncludes" runat="server">
<script type="text/javascript" src="@Url.Content("/Scripts/SomeScript.js")" />
</asp:Content>
剃须刀:
@section JavaScriptIncludes
{
<script type="text/javascript" src="@Url.Content("/Scripts/SomeScript.js")" />
}
还可以考虑使用 HTML Helper 来呈现<script>
标签。