【发布时间】:2016-05-28 19:54:38
【问题描述】:
我在下面的_Layout.cshtml 创建了两个渲染部分:
@RenderSection("scripts", required: false)
@RenderSection("scriptpartial", required: false)
Page Index.cshtml 使用来自_Layout.cshtml 的引用,在页面Index.cshtml 我使用定义代码:
@section scripts {
<script type="text/javascript">
$(document).ready(function () {
alert("This is code 1");
});
</script>
}
页面Index.cshtml包含一个部分_Other.cshtml,在文件_Other.cshtml我定义代码:
@section scriptpartial {
<script type="text/javascript">
$(document).ready(function () {
alert("This is code 2");
});
</script>
}
当我运行应用程序时,只执行了“This is code 1”,我不知道这个错误
【问题讨论】:
-
@sections 在部分视图中被忽略。您必须从 _Layout 或 index 渲染它。
标签: jquery asp.net-mvc razor