1

I render section in HEAD od HTML page and PartialView in the middle of the page like the code shows below

<html>
<head>
    @RenderSection("Scripts", false)
</head>
.....
    @Html.Partial("_MenuAdmin")
</html>

In PartialView _MenuAdmin I have some javascript.

@section Scripts
{
    <script type="text/javascript">
        alert("Test");
    </script>
}

So, the problem is that same JavaScript code doesn't loaded. If instead PartialView I use View JavaScript loaded properly.

How I can load JavaScript in my sample?

tereško
  • 58,060
  • 25
  • 98
  • 150
SilverDeveloper
  • 187
  • 2
  • 13
  • There are some very compelling reasons why you shouldn't put your JS (or at least the majority of it) in the head of your page but instead should move it to the end. http://developer.yahoo.com/performance/rules.html#js_bottom – Levi Botelho Oct 26 '12 at 08:27
  • 2
    Take a look here, this may already be answered... http://stackoverflow.com/questions/7556400/injecting-content-into-specific-sections-from-a-partial-view-asp-net-mvc-3-with – Christian Phillips Oct 26 '12 at 08:33

1 Answers1

1

@section is not supported inside a Partial View, you should use @Scripts.Render directly in your view.

Stefan P.
  • 9,489
  • 6
  • 29
  • 43