skip to Main Content

I have a project that I am building with .NET Core 6. I have installed a bootstrap package via Libman, stored under "lib/twitter-bootstrap/css/bootstrap.css". I am having some problems linking to this file from the ‘_layout.cshtml’ file in my ‘Views/Shared’ folder. I wondered if anyone knows of the correct way to hyperlink.

Code of _layout.cshtml is below:

    <!DOCTYPE html>
    <html>
        <head>
            <meta name="viewport" content="width=device-width" />
            <title>SportsStore</title>
            <link href="./twitter-bootstrap/css/bootstrap.css" rel="stylesheet" />
        </head>
        <body>
            <div class="bg-dark text-white p-2">
                <span class="navbar-brand ml-2">SPORTS STORE</span>
            </div>
            <div class="row m-1 p-1">
                <div id="categories" class="col-3">
                    Put something useful here later
                </div>
                <div class="col-9">
                    @RenderBody()
                </div>
            </div>
        </body>
    </html>

Screenshot of folder structure of my .NET Core project:

screenshot of folder structure

I would be very grateful for any advice.

Thanks,

Robert

London, UK

2

Answers


  1. Firstly,make sure you’ve calledapp.UseStaticFiles()in Program.cs.If you haven’t modifyed FileProvider ,create a folder named of "wwwroot" and move your static files into it.Also you could try

    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
               Path.Combine(builder.Environment.ContentRootPath, "foldername")),
        
    });
    

    For more details,you could check this document

    Secondly,try with

    "~/lib/twitter-bootstrap/css/bootstrap.css"
    

    If you moved the folder into wwwroot folder

    Login or Signup to reply.
  2. You can try this :

    @Styles.Render("~/twitter-bootstrap/css/bootstrap.css")
    

    (instead of : )

    <link href="./twitter-bootstrap/css/bootstrap.css" rel="stylesheet" />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search