What is @section scripts{}? And how to use it?
Your section scripts may like this:
@section scripts{
<script type="text/javascript">
function load() {
$.get('@Url.Action("Results")?teamcode=' + teamcode + '&orderby=' + orderby+'&page=1&size=10', function (data) {
$('#results').html(data);
})
}
</script>
}
It's placed in a view page.
If you run it directly, it will report an error.
Yes, if you write like this, you must add a @RenderSection("scripts", required: false) to the layout page.
This part of your javascript will become part of the layout page.
The main advantage of writing this way is to make the layout page look more concise.
As a reminder, you can write @RenderSection("scripts", required: false) directly on the layout page, and you don't need to write @section Scripts{} in the sub-page, but if you write @section Scripts{} in the sub-page, then You must write @RenderSection("scripts", required: false) on the layout page, otherwise the same error as mentioned above will be reported.