System.Web.Optimization已安装
捆绑包配置如下

using System.Web.Optimization;
public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/Content/themes/base/js").Include("~/Scripts/Site.js"));
        bundles.Add(new StyleBundle("~/Content/themes/base/css").Include("~/Content/Site.css"));

    }
}

将此添加到layout.cshtml
@System.Web.Optimization.Scripts.Render("~/Content/themes/base/js")
@System.Web.Optimization.Styles.Render("~/Content/themes/base/css")

css缩小成功,但返回404错误的js文件?

最佳答案

确保bundleContent/themes/base/js的虚拟路径与实际路径不相关。因此,通常我们在虚拟路径中使用~/bundles
例子

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/base/js").Include("~/Scripts/Site.js"));
    bundles.Add(new StyleBundle("~/bundles/base/css").Include("~/Content/Site.css"));

}

08-15 17:47