Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding bootstrap in bundleconfig doesn't work in asp.net mvc

I met an issue, strange in my point of view.

I installed bootstrap via nuget package console.

After that, in BundleConfig.cs file, I added two items to bundles list:

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(                     "~/Scripts/bootstrap.min.js"));  bundles.Add(new StyleBundle("~/Content/bootstrap").Include(                      "~/Content/bootstrap.min.css",                       "~/Content/bootstrap-theme.min.css")); 

Of course, these files exist locally.

The _Layout.cshtml file contains

<!DOCTYPE html> <html> <head>     <meta charset="utf-8" />     <meta name="viewport" content="width=device-width" />     <title>@ViewBag.Title</title>     @Styles.Render("~/Content/css")     @Scripts.Render("~/bundles/modernizr")     @Styles.Render("~/Content/bootstrap")  </head> <body>     @RenderBody()      @Scripts.Render("~/bundles/jquery")     @Scripts.Render("~/bundles/bootstrap")     @RenderSection("scripts", required: false) </body> </html> 

But when I see a view (for example login page), I see that bundle doesn't append bootstrap part.

<!DOCTYPE html> <html> <head>     <meta charset="utf-8" />     <meta name="viewport" content="width=device-width" />     <title>Login</title>     <link href="/Content/Site.css" rel="stylesheet"/>     <script src="/Scripts/modernizr-2.6.2.js"></script>         <!-- I expect bootstrap here but it is not displayed --> </head> <body>  ...  <script src="/Scripts/jquery-1.9.1.js"></script> <!-- I expect bootstrap here but it is not displayed --> </body> </html> 
like image 760
Snake Eyes Avatar asked Jan 01 '14 14:01

Snake Eyes


People also ask

How can add bootstrap in ASP.NET MVC?

Go to the References folder right click on the folder >Find>Manage NuGet Packages>Click on the option. Install bootstrap package. Bootstrap is installed automatically and css files are saved in content folder and js files are saved in script folder.

What is BundleConfig Cs in ASP.NET MVC?

Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load performance.

How do I import bootstrap into Visual Studio?

To install the Bootstrap Snippet Pack, from Visual Studio, go to Tools, then Extensions and Updates > Online > Search Bootstrap Snippet Pack. Once Installed, from Visual Studio editor, hit CTL+K, CTL+X to bring in the snippet tool. Then select Bootstrap and the component needed.

What is the use of BundleConfig in MVC?

To improve the performance of the application, ASP.NET MVC provides inbuilt feature to bundle multiple files into a single, file which in turn improves the page load performance because of fewer HTTP requests.


1 Answers

When using Bundle, do not append the .min

bundles.Add(new StyleBundle("~/Content/bootstrap").Include(     "~/Content/bootstrap.css",      "~/Content/bootstrap-theme.css")); 

Based on the debug setting, (mostly web.config)

  • debug="true" - the non minified version will be used.
  • debug="false" - *.min.css will be searched, and if not found, the current will be minified

web.config setting:

<system.web>   <compilation debug="true"... 
like image 164
Radim Köhler Avatar answered Sep 18 '22 14:09

Radim Köhler