SilverDeveloper
SilverDeveloper

Reputation: 187

JavaScript inside Section in PartialView

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?

Upvotes: 1

Views: 861

Answers (1)

Stefan P.
Stefan P.

Reputation: 9519

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

Upvotes: 1

Related Questions