布局页面头:
<head>
<link href="@Url.Content("~/Content/themes/base/Site.css")"
rel="stylesheet" type="text/css" />
</head>
Run Code Online (Sandbox Code Playgroud)
应用程序需要的View(AnotherView):
<link href="@Url.Content("~/Content/themes/base/AnotherPage.css")"
rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
和AnotherView有一个局部视图(AnotherPartial)需要:
<link href="@Url.Content("~/Content/themes/base/AnotherPartial.css")"
rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
问题:我们如何将这些CSS文件链接添加到Layouthead和AnotherPartial链接到Layout头?
RenderSection不是一个好主意,因为AnotherPage可以有多个Partials.添加所有CSS到头部是没用的,因为它将动态更改(它取决于Anotherpages).
我想知道为什么我的js文件在我在视图中调用时工作:
@section Scripts {
<script>
function myFunction() {
alert("Hello1");
}
</script>
}
Run Code Online (Sandbox Code Playgroud)
但是当我打电话时它不起作用:
@section Scripts {
<script type="text/javascript" src="~/Views/Home/script.js"></script>
<script>
myFunction();
</script>
}
Run Code Online (Sandbox Code Playgroud)