I'm using MVC 3 with the Razor view engine and I would like to inject scripts from multiple views into one centrally defined $(document).ready(); function in the master page.

I have tried the following:

<script type="text/javascript">
    $(document).ready(function () {
      //OnLoad Script load area
      '@RenderSection("DocumentReady", false)'
    });
</script>

In my master view, and then:

@section DocumentReady{
    alert('Document is ready!');
}

In my view, but unsuprisingly, we get compilation errors due to the javascript not being within a <script> tag.

If there are a lot of small view controls that need to run some initialisation script in the $(document).ready() function, it would be nice to keep them all together in a single place.

Is there a way to inject javascript to a master view without the surrounding <script> tags and without affecting compilation?

Edit
Report