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

1
  • 4
    @sections are ignored in partial views. You have to render it from _Layoout or index. Commented Feb 17, 2016 at 8:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.