简体   繁体   English

无法捆绑和缩小以在MVC4上工作

[英]Can't get bundling and minification to work on MVC4

I'm trying to bundle and minify my css and js files with a MVC4 application but can't get it to work. 我正在尝试使用MVC4应用程序捆绑并缩小我的CSS和JS文件,但无法使其正常工作。 I installed the Microsoft.Web.Optimization package making use of the package manager console. 我使用程序包管理器控制台安装了Microsoft.Web.Optimization程序包。

I included the following statement in my HTML 我在HTML中包含以下语句

<link rel="stylesheet" href="Styles/Layout/CSS" />

But my stylesheets are not loading. 但是我的样式表没有加载。 Is there anything I'm missing? 有什么我想念的吗?

Assuming you've setup that bundle in BundleConfig.cs in your App_Start folder then you should just need to add this line in your _layout.cshtml : 假设您已经在App_Start文件夹的BundleConfig.cs中设置了该捆绑包,那么您只需要在_layout.cshtml添加以下行:

 @Styles.Render("~/Styles/Layout/CSS") 

The path of the bundle should be the same as in the BundleConfig.cs file 捆绑包的路径应与BundleConfig.cs文件中的路径相同

If you don't have a BundleConfig.cs file then the easiest thing to do is create a new MVC application project (internet application template) and follow the example there. 如果您没有BundleConfig.cs文件,那么最简单的方法是创建一个新的MVC应用程序项目(Internet应用程序模板),然后按照此处的示例进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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