Kaan Eroğlu
Kaan Eroğlu

Reputation: 63

How to use css files or js in Area on ASP .NET Core

You know ASP .NET Core MVC has a wwwroot static files folder. I need to put my custom js, css etc. into Content folder under Areas folder. Anyone tried this before or anyone know how to do this?

Upvotes: 3

Views: 2178

Answers (1)

Saeed Mardomi
Saeed Mardomi

Reputation: 139

If the structure of our area is as follows :

enter image description here

You need to Copy these codes to the Configure section in Startup under the app.UseStaticFiles()

app.UseStaticFiles(new StaticFileOptions()
   {
     FileProvider = new 
     PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), 
     "Areas\\Foo\\Content")),
      RequestPath = new PathString("/Foo/Content")
   });

and link the file like below :

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

Upvotes: 4

Related Questions