Trong dự án ASP.NET MVC3 của tôi, tôi có một tiêu chuẩn _Layout.cshtml
tạo ra bởi Visual Studio 2010 và sau khi đóng thẻ <body>
của tôi, tôi đặt một RenderSection
:RenderSection không làm việc bên trong phần Xem trong ASP.NET MVC3
_Layout.cshtml :
</body>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
@RenderSection("ScriptContent", required: false)
</html>
Sau đó, trong Index.cshtml
Xem tôi có:
@model MyApp.ViewModels.MyViewModel
@{ Html.RenderPartial("MyPartial", Model); }
Nếu tôi đặt @section ScriptContent
trong Index.cshtml nó hiển thị chính xác. Nếu tôi đặt nó trong phần Xem tôi MyPartial.cshtml
:
@model MyApp.ViewModels.MyViewModel
@section ScriptContent {
<script src="@Url.Content("~/Scripts/Filters.js")" type="text/javascript"></script>
}
Trong mã nguồn trang web của tôi, tôi có:
</body>
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
</html>
nghĩa là @section
chẳng thi hành ngay. Nguyên nhân có thể là gì? Cảm ơn
Bản sao có thể có của [Làm cách nào để hiển thị một phần trong Chế độ xem một phần trong MVC3?] (Http://stackoverflow.com/questions/13764936/how-to-render-a-section-in-a-partial-view -in-mvc3) – KyleMit