Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

asp.net mvc 4 - Why does ResolveBundleUrl not work for custom folders? (MVC Beta 4)

From a brand-new ASP.NET MVC 4 Beta Web Application, I'm re-arranging my folders to match Rob Conery's VidPub.Web example

Specifically, this means that the final directory structure for content looks like this

VidPub.Web
 |
 ---Public
    |
    |---Images
          |--- *.png 
    |---javascripts
          |--- *.js 
    |---stylesheets
         |----themes
              |---base  
                  |--- images
                  |--- *.css
        |----site.css

However, when I change the following lines in _Layout.cshtml

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Content/css")" 
           rel="stylesheet" 
           type="text/css" />

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Content/themes/base/css")" 
           rel="stylesheet" 
           type="text/css" />

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
             "~/Scripts/js")"></script>

to

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Public/stylesheets/css")"
           rel="stylesheet" 
           type="text/css" />

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Public/stylesheets/themes/base/css")" 
           rel="stylesheet" 
           type="text/css" />

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Public/javascripts/js")"></script>

I end up with absolutely nothing in the resulting HTML.

<link rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" />
<script></script>

Why isn't it picking up the files in their new locations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Under Application_Start in Global.asax.cs use BundleTable.Bundles.EnableDefaultBundles(); instead of BundleTable.Bundles.RegisterTemplateBundles();

If you look at the source for RegisterTemplateBundles you can see that it actually only looks for (and adds) specific js and css files. EnableDefaultBundleson the other hand does pretty much the same as when you add you own bundles.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...