[英]Image does not display after migration from ASP.NET MVC framework to ASP.NET Core 3.1 MVC
After migrating my ASP.NET MVC project to ASP.NET Core 3.1 MVC, the images that are in the project folders are no longer appearing in the view.将我的 ASP.NET MVC 项目迁移到 ASP.NET Core 3.1 MVC 后,项目文件夹中的图像不再出现在视图中。
Please, what is happening?请问,这是怎么回事?
<img src="@ViewBag.ImagePath" class="rounded img-fluid" alt="" id="Image1">
When using .net core you need to explicitly configure the application to serve static files like.css, .js or image files.使用 .net 核心时,您需要明确配置应用程序以提供 static 文件,如 .css、.js 或图像文件。
To configure this function go to your Startup.cs
file, then inside the method Configure(IApplicationBuilder app, IWebHostEnvironment env)
add the following line: app.UseStaticFiles();
要将此 function go 配置到您的Startup.cs
文件,然后在方法Configure(IApplicationBuilder app, IWebHostEnvironment env)
中添加以下行: app.UseStaticFiles();
before app.UseRouting();
在app.UseRouting();
If your application is already configured to serve static files, please, leave a comment below so we can work on it.如果您的应用程序已配置为提供 static 个文件,请在下方发表评论,以便我们进行处理。
Note that in .NET Core image files need to be located inside wwwroot > images
and refered like this <img src="~/images/Image1.jpg" class="rounded img-fluid" alt="" id="Image1">
请注意,在 .NET 中,核心图像文件需要位于wwwroot > images
中,并像这样<img src="~/images/Image1.jpg" class="rounded img-fluid" alt="" id="Image1">
In .net core the folder structure is different.在.net核心文件夹结构不同。 Images need to be stored in wwwroot folder.图像需要存储在 wwwroot 文件夹中。 Also you need to enable static files middleware in您还需要启用 static 文件中间件
Startup.cs启动.cs
file in归档
Configure配置
method before using MVC or routing.使用 MVC 或路由之前的方法。
app.UseStaticFiles();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.