【问题标题】:Cannot get image (ASP.NET) [duplicate]无法获取图像(ASP.NET)[重复]
【发布时间】:2017-12-08 13:51:04
【问题描述】:

我有 View 我需要从 db 获取 pic 的 src 值。

这里是查看代码

   <tbody id="findings" style="overflow-y: scroll;">
                @foreach (var item in Model)
                {
                    <tr>
                        <td class="point">
                            @(rowNo += 1)
                        </td>
                        <td style="display:none" id="patientId" class="title">
                            @Html.DisplayFor(modelItem => item.Patient_id)
                        </td>

                        <td class="title">
                            @Html.DisplayFor(modelItem => item.Patient.Date_of_Birthday)
                        </td>
                        <td id="nameVal" class="title">
                            @Html.DisplayFor(modelItem => item.Patient.Name)
                        </td>
                        <td class="title">
                            @Html.DisplayFor(modelItem => item.Start_appointment)
                        </td>
                        <td class="title">
                            <img src="@item.Calculation.CalculationStatus" />
                        </td>
                        <td class="title"></td>
                        <td class="title"></td>
                    </tr>
                 }
            </tbody>

但是当我运行时出现错误

加载资源失败:服务器响应状态为 404 (未找到)

在页面源中我有这个<td class="title"> <img src="~/images/status_icons/openedCalculation.png" /> </td>

我不明白为什么页面没有显示。

【问题讨论】:

  • 你能告诉我们你在哪里找到那个文件吗?给定路径,images 文件夹应该位于您的 Web 项目的根目录下。
  • 为了测试目的,输入资源图像文件的完整绝对路径。
  • 您是否检查过该文件是否确实存在? 404 表示在指定位置找不到资源(页面/图像/...)。
  • 是的。图片位于 project@hbulens 的根目录中
  • 是的,因为这是纯 html,而不是服务器端标记。没有什么可以取代 ~ 符号。试试&lt;img src="@Url.Content("~/images/status_icons/openedCalculation.png")" /&gt;

标签: html asp.net asp.net-mvc


【解决方案1】:

问题出在~ 符号处。没有它,一切都会正常工作。

【讨论】:

  • 是的,但是如果您只是删除了 ~,它只有在 images 处于根服务器级别时才有效。换句话说,如果你将它部署在像mywebsite.com/myapplication 这样的服务器上,由于 images 是 myapplication 的一个文件夹,它不会找到它。
猜你喜欢
  • 2020-09-12
  • 1970-01-01
  • 2022-01-20
  • 2011-04-22
  • 1970-01-01
  • 2020-11-02
  • 2011-12-01
  • 2012-11-24
  • 2018-12-09
相关资源
最近更新 更多