4

Basically after a bunch of work I've finally managed to get up and running with Bootstrap in my ASP.NET MVC4 project.

Here is my folder structure:

enter image description here

Here is my bundleconfig:

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrapjs").Include(
                        "~/Scripts/bootstrap.js"));

            bundles.Add(new ScriptBundle("~/Content/bootstrapcss").Include(
                        "~/Content/bootstrap.css",
                        "~/Content/bootstrap-responsive.css"));
         }

However when I try to add an HTML element with an icon:

<button type="submit" class="btn"><i class="icon-search"></i></button>

The icon does not appear.

1 Answer 1

3

The last bundle needs to be a StyleBundle, not a ScriptBundle. Here's an example from one of my projects:

bundles.Add(new StyleBundle("~/bundles/css").Include(
                        "~/content/css/bootstrap.min.css",
                        "~/content/css/font-awesome.min.css",
                        "~/content/css/common.css"));

I should note that I organize my CSS files into a specific folder, and this specific project uses FontAwesome in place of the Glyphicons.

As noted from the comments, the default Bootstrap package assumes that the CSS files are in one folder, and that the icon sprite file is in another folder at the same level as the CSS folder. Based on that assumption, the path to the sprite is set to "../img/glyphicons-halflings.png". If your files are not located in the same places, you need to manually edit the path, or use the Customizer to build a download that has the correct path for both the light and the dark versions of the sprite file.

Sign up to request clarification or add additional context in comments.

8 Comments

Ahh I've changed it to ScriptBundle however the icon still doesn't show up.
If you open Firebug (or your browser's native dev tools), do you see a 404 error on the sprite file?
Okay, and what is the exact path that Bootstrap is trying to load the sprite file from?
It attempts to load from: /img/glyphicons-halflings.png NOT Content
Yeah, without a initial . that path will resolve from the site root. So either change it to /content/img/glyphicons-halflings.png or add the . at the beginning.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.