简体   繁体   中英

MVC Bundling: IncludeDirectory not working as expected

I am trying to add a Scripts bundle to my MVC site. At first I explicitly named the files:

var scripts = new ScriptBundle("~/scripts/bundle")
    .Include("~/scripts/jquery-2.1.3.min.js")
    .Include("~/scripts/jquery.validate-1.13.0.min.js")
    .Include("~/scripts/jquery.validate.unobtrusive.min.js");

bundles.Add(scripts);

This works as expected. However, I then decided it would be easier to just include the whole directory:

var scripts = new ScriptBundle("~/scripts/bundle")
    .IncludeDirectory("~/scripts", "*.js", true);

bundles.Add(scripts);

This second approach does not output anything when calling @Scripts.Render() , so I can only assume the IncludeDirectory method has not found anything. What am I doing wrong?

Edit: I have also tried the wildcard syntax

var scripts = new ScriptBundle("~/scripts/bundle")
    .Include("~/scripts/*.js");

This also fails to render anything

Try:

var scripts = new ScriptBundle("~/scripts/bundle")
    .Include("~/scripts/*.js")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM