在我的ASP.NET MVC3项目,我必须通过Visual Studio 2010和关闭我的<body>
标记后生成的标准_Layout.cshtml
,我把一个RenderSection
:RenderSection不是局部视图内工作在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>
然后在我的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
。可能是什么原因?谢谢
[如何在MVC3的部分视图中渲染剖面?](http://stackoverflow.com/questions/13764936/how-to-render-a-section-in-a-partial-view -in-mvc3) – KyleMit