I want to include a javascript reference like:
<script src="@Url.Content("~/Scripts/jqueryFoo.js")" type="text/javascript"></script>
If I have a Razor View, what is the proper way to include this without having to add it to the Layout (I only need it in a single specific View, not all of them)
In aspx, we could use content place holders.. I found older examples using aspx in mvc but not Razor view..
Depending how you want to implement it (if there was a specific location you wanted the scripts) you could implement a
@sectionwithin your_Layoutwhich would enable you to add additional scripts from the view itself, while still retaining structure. e.g._Layout
View
Otherwise, what you have is fine. If you don’t mind it being “inline” with the view that was output, you can place the
<script>declaration within the view.