Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have created a bundle config file and added bundles to it. Then I have added its references in _Layout.cshtml file. but the styles and scripts are not working. but it works when I add them normally as in an html page.

My code in BundleConfig file
C#
public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                        "~/Scripts/bootstrap.js",
                        "~/Scripts/bootstrap.min.js"));
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                       "~/Scripts/jquery-1.9.0.js",
                       "~/Scripts/jquery-1.9.0.min.js",
                       "~/Scripts/jquery-1.9.0-vsdoc.js",
                        "~/Scripts/jquery-1.6.4.js",
                       "~/Scripts/jquery-1.6.4.min.js",
                       "~/Scripts/jquery-1.6.4-vsdoc.js"
                       ));
            bundles.Add(new ScriptBundle("~/bundles/jqueryUI").Include(
                       "~/Scripts/jquery-ui-1.10.3.custom.min.js",
                       "~/Scripts/jquery-ui-1.11.1.js",
                       "~/Scripts/jquery-ui.min-1.11.1.js"
                       ));
            bundles.Add(new ScriptBundle("~/bundles/jqueryLibrary").Include(
                     "~/Scripts/jquery.bxslider.js",
                     "~/Scripts/jquery.expander.min.js",
                     "~/Scripts/jquery.jscrollpane.min.js",
                     "~/Scripts/jquery.kinetic.min.js",
                     "~/Scripts/jquery.mousewheel.min.js",
                     "~/Scripts/jquery.parade.js",
                     "~/Scripts/jquery.prettyPhoto.js",
                     "~/Scripts/jquery.smoothdivscroll-1.3-min.js",
                     "~/Scripts/jquery.zweatherfeed.min.js"
                     ));
            bundles.Add(new ScriptBundle("~/bundles/scriptLibrary").Include(
                      "~/Scripts/custom_scripts.js",
                      "~/Scripts/docs.min.js",
                      "~/Scripts/google.maps.min.js",
                      "~/Scripts/ie10 - viewport - bug - workaround.js"
                      ));
            bundles.Add(new StyleBundle("~/Content/bootstrap").Include(
                "~/Content/bootstrap.css",
                "~/Content/bootstrap.min.css",
                "~/Content/bootstrap-theme.css",
                "~/Content/bootstrap-theme.min.css"));
            bundles.Add(new StyleBundle("~/Content/font-awesome").Include(
                "~/Content/font-awesome.css",
                "~/Content/font-awesome.min.css"));
            bundles.Add(new StyleBundle("~/Content/jqueryui").Include(
                "~/Content/jquery/jquery-ui-1.8.16.custom.css"));
            bundles.Add(new StyleBundle("~/Content/library").Include(
                "~/Content/jquery.bxslider.css",
                "~/Content/prettyPhoto.css",
                "~/Content/parade_smooth.css",
                "~/Content/zweatherfeed.css",
                "~/Content/custom.css"
                ));
        }

Code in _Layout.cshtml
C#
@Styles.Render("~/Content/bootstrap")
    @Styles.Render("~/Content/font-awesome")
    @Styles.Render("~/Content/library")
    @Styles.Render("~/Content/jqueryui")
@Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryUI")
    @Scripts.Render("~/bundles/jqueryLibrary")
    @Scripts.Render("~/bundles/scriptLibrary")



Any one help me please..
Posted
Updated 5-Nov-14 22:14pm
v2
Comments
Vijay Gill 4-Nov-14 6:06am    
Are your viesw using the shared layout? Or is your _ViewStart.cshtml setting it up or not?

Please visit below link:

http://www.deliveron.com/blog/post/Be-Careful-When-Bundling-Stylesheets-in-MVC-4.aspx[^]

If you are using Visual Studio 2010..it is possible above link may fix your issue.
In case of any difficulty please post your query.
Thanks.
 
Share this answer
 
v2
Hi all,
I got the answer atlast. It was due to not registering the bundles in the Global.asax.cs file.
C#
BundleConfig.RegisterBundles(BundleTable.Bundles);


any way thank you all for you support..
 
Share this answer
 
v2
Additional reference.

ASP.NET MVC bundles internals[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900