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
?
You should put the stylesheet links and javascript <script> in the <head> , as that is dictated by the formats.
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.
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.
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
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