剃须刀页面如何显示图片?
How does a razor page show a picture?
剃须刀页面上有一段代码,像这样,
<img src="Images/Tree.jpg" asp-append-version="true" width="286" height="135" />
运行之后,页面无法显示图片,是不是哪里出错了?
您的 Images
文件夹应放在 wwwroot
下。
然后试试这个代码:
<img src="~/Images/Tree.jpg" asp-append-version="true" width="286" height="135"/>
更多详情可以看这个link.
如果您的 Images
静态文件在 wwwroot
文件夹之外,要提供这些文件并使其按预期工作,您可以尝试:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, "Images")),
RequestPath = "/Images"
});
//...
然后输入URL即可访问
剃须刀页面上有一段代码,像这样,
<img src="Images/Tree.jpg" asp-append-version="true" width="286" height="135" />
运行之后,页面无法显示图片,是不是哪里出错了?
您的 Images
文件夹应放在 wwwroot
下。
然后试试这个代码:
<img src="~/Images/Tree.jpg" asp-append-version="true" width="286" height="135"/>
更多详情可以看这个link.
如果您的 Images
静态文件在 wwwroot
文件夹之外,要提供这些文件并使其按预期工作,您可以尝试:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, "Images")),
RequestPath = "/Images"
});
//...
然后输入URL即可访问