How to add js and css files in ASP.net Core?
The better way to do it is to use: app.UseStaticFiles();
inside startup.cs
before routing.
It might be a bit late to answer the question, but for the ones who come here via Google: I found that adding asp-append-version="true"
worked for me, as all the other options given in the other answers were already provided in _Layout.cshtml
.
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