I want to be able to able to register script blocks in the ViewData or ViewBag and then unload them on my layout page at the correct position.
I tried writing a @function {}
in my _Layout
but this cannot be called from my Views.
So how do I write a class that allows me to do something similar to
@Something.registerscript("myscript.js")
And then on the Layout page
@Something.RenderScripts()
I saw an implementation using the singleton pattern here...
Add CSS or JavaScript files to layout head from views or partial views
But im afraid that will cause problems as this should be dynamic not static!