Include Scripts from Feature folder in ScriptBundle

453 views Asked by At

I'm trying to include js files that are not part of the original ~/Scripts folder included in a MVC web project. Rather I have my script files inside of my Feature folder like: ~/Features/MyNewFeature/Scripts

However when running the app I get nothing but 404 errors when the request goes to find those js files. I'm not sure what I'm missing or if there's something that needs to be added to make this work. I know I've read that js files have to be in the Scripts folder but I'm having a hard time believing that since there's a way around not having your cshtml files inside a /Views folder.

 bundles.Add(new ScriptBundle("~/bundles/mynewfeature")
                  .Include("~/Features/MyNewFeature/Scripts/Settings.js"));

Then to render in cshtml:

 @Scripts.Render("~/bundles/mynewfeature")
1

There are 1 answers

0
TMan On

So the problem was first starting once the/Views Web.config got moved to the Features folder. To fix the problem I was able to add a new handler that explicitly allows js files.

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler" />
      <add name="JavaScript" path="*.js" verb="GET, HEAD" type="System.Web.StaticFileHandler" />
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>