Lucas David Ferrero
Lucas David Ferrero

Reputation: 1902

I can't serve css files ASP MVC

I'm using dotnetcore and ASP MVC. The problem is that I don't know how to serve correctly my css and images files. Here you can see the file structure:

file structure

Here is the Shared layout's head.

    <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Galeria de comics">
        <title>@ViewBag.Title - Galeria de comics</title>
        <link rel="stylesheet" href="~/wwwroot/css/normalize.css">
        <link rel="stylesheet" href="~/wwwroot/css/main.css">
    </head>
    <body>
        <header class="main-header"></header>
        @RenderBody()

    </body>
</html>

I'm called this layout in a View.

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "Libro comic detalle";
}

What's the problem? The problem is that the CSS files aren't serve so I can't see the styles. Any solition?

Upvotes: 1

Views: 1235

Answers (1)

Lucas David Ferrero
Lucas David Ferrero

Reputation: 1902

Seems I miss the href attribute's content. You should skip the wwwroot folder since the static files are served as http://app/css/cssFileName. Example: http://yoursite.com/css/main.css, same with images and js files.

Here I fixed the problem:

<link rel="stylesheet" href="~/css/normalize.css">
<link rel="stylesheet" href="~/css/main.css">

If you want to know more visit this link

Upvotes: 1

Related Questions