gigi
gigi

Reputation: 3936

How to include JavaScript and CSS from custom directories in ASP.NET MVC 4, .net 4.5?

Considering this folder structure:

Content
     style1.css
     style2.css
     CssFolder1
         style3.css
         style4.css
         style5.css
         style6.css

In the application, I want to include style1.css, style2.css, style3.css and style4.css.

I am doing this:

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new StyleBundle("~/styles/main").Include("~/Content/style1.css",   "~/Content/style2.css"));
        bundles.Add(new StyleBundle("~/styles/custom").Include("~/Content/CssFolder1/style3.css","~/Content/CssFolder1/style4.css"));
    }
}

And in _Layout.cshtml I render it like this:

@Styles.Render("~/styles/main", "~/styles/custom")

Only style1.css and style2.css are loaded. How to correctly load style3.css and style4.css?

LE: Content is a folder from the solution, all files within that folder are added to the solution.

Upvotes: 2

Views: 2919

Answers (1)

George Stocker
George Stocker

Reputation: 57872

All files need to be added to the project in the Visual Studio solution window. Right click on the css folder and click add existing item. Navigate to the styles3.css and add it that way.

Upvotes: 1

Related Questions