MVC 4 bundleconfig.cs文件,不包括在layout.cshtml中

时间:2015-05-10 15:02:53

标签: c# asp.net-mvc asp.net-mvc-4 razor

BundleConfig.cs

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {

        bundles.Add(new StyleBundle("~/resources/css").Include("~/resources/css/reset.css", 
            "~/resources/css/style.css", "~/resources/css/invalid.css"));

        bundles.Add(new ScriptBundle("~/resources/scripts").Include("~/resources/scripts/jquery-1.3.2.min.js",

            "~/resources/scripts/simpla.jquery.configuration.js", "~/resources/scripts/facebox.js",
            "~/resources/scripts/jquery.wysiwyg.js"));
    }
}

Layout.cshtml

 @Styles.Render("~/resources/css")
 @Scripts.Render("~/resources/scripts")

它在html中呈现的内容

 <link href="/resources/css" rel="stylesheet"/>
<script src="/resources/scripts"></script>

不包括html中的css和js文件路径

1 个答案:

答案 0 :(得分:1)

在应用程序启动时添加global.asax文件

BundleConfig.RegisterBundles(BundleTable.Bundles);