I realise this has been asked quite a few times for different languages / versions of .NET and MVC.
With MVC4, what is currently the accepted way to register a Javascript Startup Script? I want to fire a script off after the page has finished loading, is there a built in method or should I just be using jQuery to do it?
“Registering Startup Scripts” is a concept derived from ASP.Net WebForms, MVC has no such concept. To reference a “global” script file to be used on multiple pages add the script reference (
<script></script>) to a Master View. To reference a script that is used on a single page/view reference it in the view itself.MVC promotes Separation of Concerns enabling you to separate your view logic (scripts) from your domain/routing logic. Thus, mixing JavaScript, which is a client-side technology, with server-side code is mitigated if not eliminated.
ASP.Net 4 does come with Script Bundling & Minification abilities which would enable the bundling & minification of script references to better manage scenarios where an application has numerous script files.
http://www.beletsky.net/2012/04/new-in-aspnet-mvc4-bundling-and.html