1

我正在使用带有 .NET Framework 4 的 MVC 3 捆绑和缩小。创建BundleConfig.cs并放在App_Data文件夹下。从Global.asax文件中调用
。 从我调用的主文件BundleConfig.RegisterBundles(BundleTable.Bundles);Application_Start()

<% Styles.Render("~/Content/themes/base"); %>
<% Scripts.Render("~/Scripts","~/Scripts/Controllers","~/Scripts/Views");%> 

在标题标签上。
然而,CSS 未按预期呈现,jQuery 未按Scripts.Render预期工作。

我的BundleConfig.cs类定义如下...

 public class BundleConfig
 {
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new StyleBundle("~/Content/themes/base").Include(
            "~/Content/themes/base/Blueprint-Liquid.css",
            "~/Content/themes/base/ex.css",
            "~/Content/themes/base/exNav.css",
            "~/Content/themes/base/ie.css",
            "~/Content/themes/base/jquery-ui-1.8.14.custom.css",
            "~/Content/themes/base/jquery.qtip.css",
            "~/Content/themes/base/reset.css",
            "~/Content/themes/base/Site.css",
            "~/Content/themes/base/structure-fixed.css",
            "~/Content/themes/base/structure-fluid.css",
            "~/Content/themes/base/tipsy.css",
            "~/Content/themes/base/typography.css",
            "~/Content/themes/base/ui.jqgrid.css")
        );

        bundles.Add(new ScriptBundle("~/Scripts/Controllers").Include(
            "~/Scripts/Controllers/ProjectController.js",
            "~/Scripts/Controllers/RequestController.js",
            "~/Scripts/Controllers/SystemController.js")
        );

        bundles.Add(new ScriptBundle("~/Scripts/Views").Include(
            "~/Scripts/Views/ProjectView.js",
            "~/Scripts/Views/RequestView.js",
            "~/Scripts/Views/SystemView.js")
        );

        bundles.Add(new ScriptBundle("~/Scripts").Include(
              "~/Scripts/Dialog.js",
              "~/Scripts/EX.Computing.js",
              "~/Scripts/exNav.js",
              "~/Scripts/grid.locale-en.js",
              "~/Scripts/jquery-1.6.2.js",
              "~/Scripts/jquery-1.6.2.min.js",
              "~/Scripts/jquery-ui-1.8.14.js",
              "~/Scripts/jquery-ui-1.8.14.min.js",
              "~/Scripts/jquery.jqGrid.fluid.js",
              "~/Scripts/jquery.jqGrid.min.js",
              "~/Scripts/jquery.jqGrid.src.js",
              "~/Scripts/jquery.qtip.js",
              "~/Scripts/jquery.tipsy.js",
              "~/Scripts/jquery.jquery.unobtrusive-ajax.js",
              "~/Scripts/jquery.jquery.unobtrusive-ajax.min.js",
              "~/Scripts/jquery.jquery.validate-vsdoc.js",
              "~/Scripts/jquery.validate.js",
              "~/Scripts/jquery.validate.min.js",
              "~/Scripts/jquery.validate.unobtrusive.js",
              "~/Scripts/jquery.validate.unobtrusive.min.js",
              "~/Scripts/json2.js",
              "~/Scripts/Labels.js",
              "~/Scripts/modernizr-1.7.js",
              "~/Scripts/SessionTimeOut.js",
              "~/Scripts/underscore.js")
       );

       BundleTable.EnableOptimizations = true; 
   }

我想知道我错过了什么?非常感谢任何帮助!

谢谢, 拉马尼

4

2 回答 2

2

当我开始使用 Bundling and Minification 时,我不确定它是否适用于 MVC3,但发现它没有任何问题。我想在这里分享我的代码,以便对某人有所帮助。

using System.Web.Optimization;

namespace Ex.Computing
{
  public class BundleConfig
  {
    public static void RegisterBundles(BundleCollection bundles)
    {
         bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(

                        "~/Content/themes/base/reset.css",
                        "~/Content/themes/base/Blueprint-Liquid.css",
                        "~/Content/themes/base/jquery-ui-1.8.23.custom.css",
                        "~/Content/themes/base/typography.css",
                        "~/Content/themes/base/eXNav.css",
                        "~/Content/themes/base/structure-fluid.css",
                        "~/Content/themes/base/eX.css",
                        "~/Content/themes/base/ui.jqgrid.css",
                        "~/Content/themes/base/Site.css",
                        "~/Content/themes/base/jquery.qtip.css"



                       )
                 ); 


         bundles.GetBundleFor("~/Content/themes/base/css").Orderer = new AppCssOrderer();


         var bootstrapOrdering = new BundleFileSetOrdering("bootstrap");

         bundles.Add(new ScriptBundle("~/Scripts/js").Include(
             "~/Scripts/eXNav.js",
             "~/Scripts/jquery-1.8.1-vsdoc.js",
             "~/Scripts/jquery-1.8.1.js",
             "~/Scripts/jquery-ui-1.8.23.custom.min.js",
             "~/Scripts/Labels.js",
             "~/Scripts/Dialog.js",
             "~/Scripts/SessionTimeOut.js",
             "~/Scripts/jquery.qtip.js",
             "~/Scripts/json2.js",
             "~/Scripts/jquery.watermark.min.js",
             "~/Scripts/grid.locale-en.js",
             "~/Scripts/jquery.jqGrid.src.js",
             "~/Scripts/jquery.jqGrid.fluid.js",
             "~/Scripts/jquery.validate.min.js",
             "~/Scripts/jquery.validate.unobtrusive.min.js",
             "~/Scripts/Computing.js",
             "~/Scripts/Controllers/ProjectController.js",
             "~/Scripts/Controllers/RequestController.js",
             "~/Scripts/Controllers/SystemController.js",
             "~/Scripts/Views/ProjectView.js",
             "~/Scripts/Views/RequestView.js",
             "~/Scripts/Views/SystemView.js"

              )
        );

         bundles.GetBundleFor("~/Scripts/js").Orderer = new AppJsOrderer();

         BundleTable.EnableOptimizations = true; 

      }
  }

  public class AppCssOrderer : IBundleOrderer 
  { 
    public IEnumerable<System.IO.FileInfo> OrderFiles(BundleContext context,   
    IEnumerable<System.IO.FileInfo> files)
    { 
       // return files.OrderBy(f => f.Name == "eyNav.css" ? -1 : 1); 
        if (context == null)
            throw new ArgumentNullException("context");

        if (files == null)
            throw new ArgumentNullException("files");

        return files;
    }
  }

  public class AppJsOrderer : IBundleOrderer
  {
    public IEnumerable<System.IO.FileInfo> OrderFiles(BundleContext context, 
    IEnumerable<System.IO.FileInfo> files)
    {
        // return files.OrderBy(f => f.Name == "eyNav.css" ? -1 : 1); 
        if (context == null)
            throw new ArgumentNullException("context");

        if (files == null)
            throw new ArgumentNullException("files");

        return files;
    }
  }
}
于 2012-10-05T21:12:28.373 回答
1

欢迎加入我们的俱乐部:Microsoft ASP.NET Web Optimization Framework 1.0.0 调试模式错误

我用下一个代码解决了这个问题,但我不喜欢这个解决方案:

BundleTable.EnableOptimizations = true;
于 2012-09-28T19:57:37.580 回答