Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

I have this section defined in my _Layout.cshtml

@RenderSection("Scripts", false)

I can easily use it from a view:

@section Scripts { 
    @*Stuff comes here*@
}

What I’m struggling with is how to get some content injected inside this section from a partial view.

Let’s assume this is my view page:

@section Scripts { 

    <script>
        //code comes here
    </script>
}

<div>
    poo bar poo
</div>

<div>
  @Html.Partial("_myPartial")
</div>

I need to inject some content inside the Scripts section from _myPartial partial view.

How can I do this?

23 Answers
23

Leave a Comment