2

I create two Render Section on _Layout.cshtml bellow:

@RenderSection("scripts", required: false)
@RenderSection("scriptpartial", required: false)

Page Index.cshtml using reference from _Layout.cshtml, on page Index.cshtml I use define code:

@section scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            alert("This is code 1");
        });
    </script>
}

Page Index.cshtml contain one partial _Other.cshtml, in file _Other.cshtml I define code:

@section scriptpartial {
    <script type="text/javascript">
        $(document).ready(function () {
            alert("This is code 2");
        });
    </script>
}

When I running application, only "This is code 1" executed, I do not know error this

teo van kot
  • 12,350
  • 10
  • 38
  • 70
M.Peter
  • 75
  • 1
  • 10

1 Answers1

0

You have to place your scriptpartial section on the Index.cshtml page, because unfortunately @sections are not possible in partial views.

slfan
  • 8,950
  • 115
  • 65
  • 78