ASP.NET MVC3プロジェクトには、_Layout.cshtml
Visual Studio 2010によって生成された標準があり、<body>
タグを閉じた後、:を配置しRenderSection
ます。
_Layout.cshtml:
</body>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
@RenderSection("ScriptContent", required: false)
</html>
それから私のIndex.cshtml
見解では私は持っています:
@model MyApp.ViewModels.MyViewModel
@{ Html.RenderPartial("MyPartial", Model); }
@section ScriptContent
Index.cshtmlに配置すると、正しく表示されます。パーシャルビューに配置した場合MyPartial.cshtml
:
@model MyApp.ViewModels.MyViewModel
@section ScriptContent {
<script src="@Url.Content("~/Scripts/Filters.js")" type="text/javascript"></script>
}
私のページソースには次のものがあります。
</body>
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
</html>
意味@section
は実行されません。原因は何でしょうか?ありがとう