Given MVC3 and Razor engine, I got
_MasterLayout.cshtml
@RenderSection("JavaScript", required: false)
..
..
@RenderBody()
..
View.cshtml with _MasterLayout.cshtml defined in _ViewStart.cshtml
..
@Html.RenderAction("PartialView", "PartialController")
..
PartialView.cshtml
..
@section JavaScript
{
........
}
..
How can I make sure that JavaScript from Partial View ends up in the Master Layout section?
Edit
The above scenario doesn't work because the partial view doesn't have a master layout defined. View, on the other hand, does have Layout with RenderSection defined. If I move section JavaScript from Partial View to View, Razor knows where to render it to. But, since partial view doesn't have a layout, it doesn't know what to do with section JavaScript and thus doesn't render it anywhere.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…