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 reference
I put the JS and CSS files in an assets folder in the wwwroot
folder of my application and then used link tags in my _Layout.cshtml
to bring in the styles. Steven Sanderson has part a of a blog post where he talks about adding third party libraries here.
You could also do some sort of setup using webpack. I admit, this topic is not very straight forward.
In _layout:
@await RenderSectionAsync("Styles", required: false)
Then your view:
@section Styles{ your CSS }
Information from: https://dev.to/amjadmh73/loading-custom-css-files-in-razor-pages-4no9
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
The better way to do it is to use: app.UseStaticFiles();
inside startup.cs
before routing.