脚本和样式不呈现

时间:2015-08-29 18:15:20

标签: c# asp.net-mvc-5 web-optimization

  

脚本和样式未在页面中呈现

     

HTML源代码OF MVC ASP.NET

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width" />
        <title>@ViewBag.Title</title>   
        @Styles.Render("~/Content/css")        
    </head>

    <body >
    @Scripts.Render("~/Scripts/js")
    @RenderSection("Scripts", false)  
    </body>
</html>
  

这是我的所有脚本和样式c#的BundleConfig文件,我做了所有我知道的

  public class BundleConfig
        {
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
            public static void RegisterBundles(BundleCollection bundles)
            {
               BundleTable.EnableOptimizations = true;

                bundles.Add(new ScriptBundle("~/Scripts/js").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/angular.js",
                    "~/Scripts/ang/app.js",
                    "~/Scripts/jquery.unobtrusive-ajax.min.js",
                    "~/Scripts/jquery-ui-1.11.2.js",
                    "~/Scripts/jquery.bpopup.min.js",
                    "~/Scripts/jquery-ui.min.js",                    
                    "~/Scripts/jquery.validate.min.js",
                    "~/Scripts/jquery.validate.unobtrusive.min.js",
                    "~/Scripts/ui.dropdownchecklist-1.4-min.js",
                    "~/Scripts/sweetalert.min.js",
                    "~/Scripts/jquery.lettering.js",
                    "~/Scripts/ang/app.js",
                    "~/Scripts/js/JavaScript1.js",
                    "~/Scripts/js/JavaScript2.js"                              
                    )); 
                bundles.Add(new StyleBundle("~/Content/css").Include(
                     "~/Content/jquery-ui.css",
                     "~/Content/css/StyleSheet.css",
                     "~/Content/StyleSheet1.css"     ,
                     "~/Content/jquery-ui.css",
                     "~/Content/ui.dropdownchecklist.standalone.css",
                     "~/Content/ui.dropdownchecklist.themeroller.css",
                     "~/Content/sweetalert.css",
                     "~/Content/animate.css"    
                      ));

                // Set EnableOptimizations to false for debugging. For more information,
                // visit http://go.microsoft.com/fwlink/?LinkId=301862        
            }
  

HTML源代码的结果MVC ASP.NET,因为你可以看到没有任何脚本的样式

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width" />
        <title>Index</title> 
        <link href="/Content/css" rel="stylesheet"/>
  </head>
<body >
     <script src="/Scripts/js"></script>      
</body>
</html>

2 个答案:

答案 0 :(得分:0)

添加BundleConfig.RegisterBundles(BundleTable.Bundles);到Global.asax

答案 1 :(得分:0)

您可能正在加载jquery.ui.css两次......

"~/Content/jquery-ui.css",
"~/Content/css/StyleSheet.css",
"~/Content/StyleSheet1.css"     ,
"~/Content/jquery-ui.css"

查看第一行和最后一行......