MVC Section

MVC Sections allow you to manipulate where in the DOM things appear, this is helpful for scripts that require libraries to be available.

jQuery

In the Index.cshtml file the script below requires that jQuery is loaded.

1
2
3
4
5
6
7
@section ScriptsGameController {
<script type="text/javascript">
$(document).ready(function () {
console.log("ready!");
})
</script>
}

This section can then be displayed in the _Layout.cshtml file

1
2
3
4
5
6
7
...
<script src="~/js/site.js" asp-append-version="true"></script>

@RenderSection("Scripts", required: false)
@RenderSection("ScriptsGameController", required: false)
</body>
</html>