I'm attempting to render JavaScript from a Razor Partial Page into the bottom of a (layout) Page. In Including JavaScript at bottom of page, from Partial Views Becuzz specifies that using a @section {}
might be helpful for this purpose, but such sections are not rendered from Partial Pages.
One could in theory circumvent the problem by rendering the section of JavaScript outside of the Partial Page, into the Page itself. However, this is not possible, given that I want to reference a html element inside the script, as follows:
@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 work?