MVC-1.1 BundleConfig-ScriptBundle

若雲發表於2014-11-13

App_Start中的BudleCnfig.cs中

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(

"~/Scripts/jquery-{version}.js"));

 

bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(

"~/Scripts/jquery-ui-{version}.js"));

 

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(

"~/Scripts/jquery.unobtrusive*",

"~/Scripts/jquery.validate*"));

            

 

 

            

        可以看出用到了{version} 和* 匹配的檔名來載入js庫,

        然後自己完全可以寫幾個自定義的bundles

        

     

  bundles.Add(new ScriptBundle("~/myBundles/myJqueryUi").Include(

"~/Scripts/MyTmpl/jquery-ui-{version}.js"

));

bundles.Add(new ScriptBundle("~/myBundles/myJquery").Include(

"~/Scripts/MyTmpl/jquery-{version}.js"

));

bundles.Add(new ScriptBundle("~/myBundles/myJquery").Include(

"~/Scripts/MyTmpl/jquery.{name}.js"

));

 

bundles.Add(new ScriptBundle("~/myBundles/allJquery").Include(

"~/Scripts/MyTmpl/jquery*"

)); 

 

 

  2,檢視中引用即可:

           

 @Scripts.Render("~/myBundles/allJquery"); 

 

 

 

       3,檢視瀏覽器載入:

            

         載入了全部檔案,