Linking to bootstrap css file from .NET core project

huangapple go评论74阅读模式
英文:

Linking to bootstrap css file from .NET core project

问题

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:

Linking to bootstrap css file from .NET core project

I would be very grateful for any advice.

Thanks,

Robert

London, UK

英文:

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:

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

Screenshot of folder structure of my .NET Core project:

Linking to bootstrap css file from .NET core project

I would be very grateful for any advice.

Thanks,

Robert

London, UK

答案1

得分: 0

Firstly, make sure you've called app.UseStaticFiles() in Program.cs. If you haven't modified FileProvider, create a folder named "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 the wwwroot folder.

英文:

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, &quot;foldername&quot;)),
    
});

For more details,you could check this document

Secondly,try with

&quot;~/lib/twitter-bootstrap/css/bootstrap.css&quot;

If you moved the folder into wwwroot folder

答案2

得分: 0

You can try this:

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

(instead of:)

<link href="./twitter-bootstrap/css/bootstrap.css" rel="stylesheet" />
英文:

You can try this :

@Styles.Render(&quot;~/twitter-bootstrap/css/bootstrap.css&quot;)

(instead of : )

&lt;link href=&quot;./twitter-bootstrap/css/bootstrap.css&quot; rel=&quot;stylesheet&quot; /&gt;

huangapple
  • 本文由 发表于 2023年4月11日 16:51:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75984030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定