英文:
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:
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:
<!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:
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, "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
答案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("~/twitter-bootstrap/css/bootstrap.css")
(instead of : )
<link href="./twitter-bootstrap/css/bootstrap.css" rel="stylesheet" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论