Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add js and css files in ASP.net Core?

I've been assigned to migrate an application from MVC into ASP.net Core, I'm new to ASP.net Core. In MVC we have BundleConfig.cs and in there we add references to our css and js files, how does it work in ASP.net Core? Let's say that I created a test.js and a MyStyle.css class, which is the best way to add references to it in every view? Should I place the .js and .css files inside wwwroot/js and wwwroot/css?

like image 224
AlexGH Avatar asked Oct 03 '16 19:10

AlexGH


People also ask

Where do I put CSS and js files?

You should put the stylesheet links and javascript <script> in the <head> , as that is dictated by the formats.

What is the proper place for image files JavaScript files and CSS files in a ASP.NET Core MVC web application?

The wwwroot folder is the default folder provided by ASP.Net Core for storing all the Static files such as Image files, CSS files and JavaScript JS files.

How can add JavaScript file in ASP.NET project?

OR can add in code behind. Show activity on this post. Probably the file is not in the path specified. '../../../' will move 3 step up to the directory in which the page is located and look for the js file in a folder named JS.


1 Answers

I added the references inside the _Layout view, inside the <environment> tags:

<environment names="Development">   <link rel="stylesheet" href="~/css/MyCss.css" /> </environment> 

If anyone knows a better way I would welcome it

like image 199
AlexGH Avatar answered Sep 23 '22 03:09

AlexGH