Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio ASP.NET MVC Not Loading Local bootstrap.css

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?

like image 983
user2969720 Avatar asked May 14 '14 08:05

user2969720


People also ask

Why my CSS is not working in bootstrap?

These are the possible reasons: You have a wrong or incorrect link to the bootstrap file. browser caching and history is messing with your html. Other CSS files are overriding the bootstrap file.

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.

Is ASP.NET MVC discontinued?

However, Microsoft discontinued ASP.NET MVC in 2018. While the framework still works, it isn't being actively developed, and there are no plans to release any new features or updates.


1 Answers

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.

like image 185
Paddy Avatar answered Nov 15 '22 11:11

Paddy