Reputation: 1936
How can I have JavaScript bundling working from another folder (aside from the Script folder). If I do this:
bundles.Add(new ScriptBundle("~/bundles/search").Include("~/Views/Search/*.js"));
The browser tells me the javascript file can't be found. Is it possible to do this or do all my sripts have to be in the Scripts folder?
Basically I want my Javascript included in my View subfolders
Upvotes: 6
Views: 1254
Reputation: 380
You need to change web.config
in Views
folder according this answer:
In ASP.NET MVC, how can I load script from my view folder?
Good example from Ashley Lee:
<system.webServer>
<handlers>
<add name="JavascriptViewHandler" path="*.js" verb="*"
preCondition="integratedMode" type="System.Web.StaticFileHandler" />
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*"
preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
Upvotes: 3
Reputation: 3976
Since you specifically want to only include javascript files, make the following change to your ~/Views/web.config
file, by adding the "JavascriptViewHandler" section.
<system.webServer>
<handlers>
<add name="JavascriptViewHandler" path="*.js" verb="*"
preCondition="integratedMode" type="System.Web.StaticFileHandler" />
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*"
preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
This will preserve all of the current blocking for non-javascript files.
Upvotes: 1
Reputation: 4835
I don't know if i understood your question properly, but if you want to use a script file from any folder in a View or preferably in it's Layout, you can add the following tag in <head>
section of you View
or _Layout.cshtml
:
<script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>
You can mention the complete path to your script file instead of ~/Scripts/jquery-ui.min.js
Upvotes: 0