6

I installed bootstrap using nuget package manager and the css files are now in my /Content/ folder. However, when trying to reference them using:

<link rel="stylesheet"  href="∼/Content/bootstrap.min.css" />

It doesn't work. But when referencing them using a CDN like:

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

It does work. I can't seem to figure out what is wrong as I have never had this problem before. I'm using an Empty template with MVC.

EDIT: After some playing around, I found that it was failing to load /%E2%88%BC/Content/bootstrap.css but after removing the tilda (~) it works fine. Anybody got any ideas?

5
  • Have you tried using fiddler or F12 dev tools to see if it is attempting to download the file and failing? Commented May 14, 2014 at 8:42
  • Yes it's failing to download bootstrap.css and bootstrap-theme.css. 404 not found. Commented May 14, 2014 at 9:02
  • Do any of the answers here help? stackoverflow.com/questions/10853316/… Commented May 14, 2014 at 10:25
  • 2
    I FINALLY figured out what the problem was. I'm reading an e-book for ASP.NET MVC and as the examples are big, I have to copy and paste (my fault, I know) and it turns out that the because the font is different in the book, it doesn't pick it up. So I just typed the ~ myself instead of copying the ∼ from the book. Sorry to waste everyone's time. Commented May 22, 2014 at 10:03
  • I think it is necessary to add the bundle: stackoverflow.com/questions/20869907/… Commented Nov 1, 2021 at 19:10

3 Answers 3

2

This is not a correct path, it uses the tilda, which is used on the server when rendering links in server controls in asp.net.

Instead of this:

<link rel="stylesheet"  href="∼/Content/bootstrap.min.css" />

Try this:

<link rel="stylesheet"  href="@Url.Content("∼/Content/bootstrap.min.css")" />

Assuming that you are using Razor.


Alternatively, consider looking into style and script bundling that you get with new asp.net sites. Can be very useful.

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

3 Comments

Hmm, that doesn't seem to be working. Breaks the application with "Compiler Error Message: CS1056: Unexpected character '∼'". My intellisense doesn't seem to like anything that I'm passing to the @Url.Content.
Doesn't work with passing the string in quotes either.
Sorry, missed the quotes. Having the string passed in quotes works for me.
1

Adding "app.UseStaticFiles()" to Startup.cs worked for me:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseBrowserLink();
        app.UseStaticFiles();
        app.UseMvcWithDefaultRoute();
    }
}

Comments

-2

Now only Bootsrap 3 works with local links in .Net. Terrible. :( For 4, you must use CDN :

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

Comments

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.