Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styles.Render does not load CSS files

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")
like image 984
Timigen Avatar asked Sep 11 '14 14:09

Timigen


2 Answers

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;

like image 119
Timigen Avatar answered Sep 23 '22 02:09

Timigen


You should not use a bundle name that is the path to a folder which already exists in the solution. e.g ("~/styles/css")

like image 31
Techy Avatar answered Sep 26 '22 02:09

Techy