Reputation: 4628
I'm after a way of getting my referenced .js files in my 'master' cshtml files to come through to the 'child' cshtml files.
I have something like this in the master file, so the .js files always get referenced (and indeed I get js intellisense in the master file):
if (false)
{
<script type="text/javascript" src="../scripts/jquery.js"></script>
}
However when I reference the master.cshtml file in a 'child' page like this:
@{
Layout = "~/Views/Shared/master.cshtml";
}
I get no javascript intellisense. I really don't want to have to put the script tags at the top of each child page, there are a lot of script tags, and a lot of child pages!
Upvotes: 12
Views: 3271
Reputation: 1
So you don't lose the time to figure why the trick doesn't work, this could be useful:
If you use a relative path, this seems to work only if the path points to the same application. An absolute path apparently works in all cases:
reference path="../../Scripts/jquery-1.4.4.js"
The above works as long as the referenced script file is in the same application.
reference path="http://localhost/Scripts/jquery-1.4.4.js"
The above seems to work in any case.
Upvotes: 0
Reputation: 1732
I was hoping to find a solution to this as well.
The best option I've found is to always use an external js file. Create a file something like Master.js at the top use a reference path:
/// <reference path="../../Scripts/jquery-1.4.4.js"/>
Then you can have the intellisense. You need to still include the jquery file before your new external file.
Upvotes: 1
Reputation: 53183
The Razor editor right now cannot infer which script files are in use (this is because Razor layout pages are set via code and the editor does not execute a view page). Unfortunately you will have to include those script tags if you want JavaScript IntelliSense to work in your view pages.
Upvotes: 5