I want to keep all of my JavaScript code in one section; just before the closing body
tag in my master layout page and just wondering the best to go about it, MVC style.
For example, if I create a DisplayTemplate\DateTime.cshtml
file which uses jQuery UI's DateTime Picker than I would embed the JavaScript directly into that template but then it will render mid-page.
In my normal views I can just use @section JavaScript { //js here }
and then @RenderSection("JavaScript", false)
in my master layout but this doesn't seem to work in display/editor templates – any ideas?
Best Answer
You could proceed with a conjunction of two helpers:
and then in your
_Layout.cshtml
:and somewhere in some template: