When attempting to use the Bundles in a MVC5 application. The CSS files fail to load, when I inspect the source I see the following reference in the HTML :
<link href="/Content/css" rel="stylesheet"/>
Why isn't this working as I expect? I have tried using different virtual paths, but that doesnt seem to work.
My BundleConfig.cs file:
using System.Web;
using System.Web.Optimization;
namespace Navi
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
Then in my _Layout.cshtml I have the following:
@Styles.Render("~/Content/css")
My issue here was I needed to add the following to the global.asax file:
BundleConfig.RegisterBundles(BundleTable.Bundles);
This also required that I include: using System.Web.Optimization;
You should not use a bundle name that is the path to a folder which already exists in the solution.
e.g ("~/styles/css")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With