Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor MVC render section

I am using master layout of Razor MVC that have something like this

@RenderSection("scripts", required: false)

And have partival view

_partial.cshtml

That have this

@section scripts
{
    @Scripts.Render("~/bundles/jquery")
}

And another partial in partial

_partial_inside_partial.cshtml

That also have

@section scripts
{
    <script>
       $('div').addClass('red');
    </script>
}

The problem i have this code inside partial, its load at he middle of the page, and jquery is at the bottom?

like image 217
Miomir Dancevic Avatar asked Dec 04 '14 09:12

Miomir Dancevic


1 Answers

Sections don't work the same way in partial views. In order to achieve what you're after, your going to have to move your scripts to a file, include an HTML helper, then call that HTML helper to render your scripts for each partial view that is loaded.

Use this as a reference: Using sections in Editor/Display templates

like image 52
Ashley Lee Avatar answered Oct 26 '22 07:10

Ashley Lee