12
部分からかみそりのセクションを作成する
これを実行しようとする私の主な動機は、ページの下部にあるパーシャルでのみ必要なJavascriptを残りのJavaScriptとともに取得し、パーシャルがレンダリングされるページの中央では取得しないことです。 これが私がやろうとしていることの簡単な例です: 本文の直前にスクリプトセクションがあるレイアウトです。 <!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> </head> <body> @RenderBody() <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script> @RenderSection("Scripts", false) </body> </html> このレイアウトを使用したビューの例を次に示します。 <h2>This is the view</h2> @{Html.RenderPartial("_Partial");} @section Scripts { <script type="text/javascript"> alert("I'm a view."); </script> } そして、これがビューからレンダリングされている部分です。 <p>This is the partial.</p> @* this never makes it into …