I'm trying to display JavaScript code from a Razor Partial Page at the bottom of a (layout) Page. In a similar discussion on Stack Overflow about Including JavaScript at bottom of page, from Partial Views, it was suggested by user Becuzz that using a @section {}
could be useful for this purpose. However, sections like this are not rendered from Partial Pages.
One potential solution is to move the section of JavaScript code outside of the Partial Page and into the main Page itself. But in my case, I need to reference an HTML element within the script, like so:
@section ScriptTag
{
<script type="text/javascript">
var example = $('#@Html.FieldIdFor(m => m.ExampleProperty)').val();
});
</script>
}
@Html.TextBoxFor(m => m.ExampleProperty)
How can I make this setup function correctly?