【问题标题】:Using ASP.NET Core MVC, how do I display an image?使用 ASP.NET Core MVC,如何显示图像?
【发布时间】:2022-01-08 14:04:42
【问题描述】:

我正在尝试为我正在创建的图库页面显示图像。我对 ASP.NET Core MVC 很陌生。我将图像保存在我的项目所在的同一文件夹中。

这是我的视图文件中的内容:

@{
    ViewData["Title"] = "Gallery";
}
<h2>Gallery Page</h2>
<img src="myImage.jpg" height="113" width="113" border="0" />

这是我的控制器中的画廊功能:

public IActionResult Gallery()
{
    return View();
}

This is my output

感谢您的帮助!

【问题讨论】:

标签: c# html asp.net-core-mvc


【解决方案1】:

在 img src 中,您直接给出了图像名称,而不是创建新的图像文件夹并将图像文件添加到该文件夹​​中。修改下面给出的html代码。

&lt;img src="~/Folder Name/myImage.jpg" height="113" width="113" border="0" /&gt;

【讨论】:

    猜你喜欢
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    • 2016-08-07
    • 2017-01-26
    • 1970-01-01
    • 2014-08-25
    相关资源
    最近更新 更多