简体   繁体   English

使用保存在数据库C#中的图像路径检索图像

[英]retrieve image using image path saved in the database c#

I need to do something like this. 我需要做这样的事情。

在此处输入图片说明

I tried using switch statement and this is the result 我尝试使用switch语句,这是结果

在此处输入图片说明

Now I tried a different approach. 现在,我尝试了另一种方法。 I saved the file path of the image in the database. 我将图像的文件路径保存在数据库中。 Then retrieve the file path from the database so that it will display the corresponding image and this is the result 然后从数据库中检索文件路径,以便它将显示相应的图像,这就是结果

在此处输入图片说明

instead of displaying the image it displayed the image path from the database. 而不是显示图像,而是显示数据库中的图像路径。 How can I resolve this? 我该如何解决?

Here's my code: 这是我的代码:

_DeliveryDetailsPartial _DeliveryDetailsPartial

    <h5 style="text-transform:uppercase; padding-left:5px; margin-top:10px; font-weight:bold">Payments Accepted</h5>
    @foreach (StoreAcceptedPayment payment in Model.Item4)
    {
        <span class="col-md-3">@Html.DisplayFor(model => payment.ImgPath)</span>
    }

DeliverController DeliverController

public ActionResult GetStoreDetails(string id)
    {
        var store = new Tuple<List<Store>, List<StoreHour>, List<StoreHour>, List<StoreAcceptedPayment>>
        (_repo.GetStore(int.Parse(id)), _repo.GetStoreHourByDay(dayOftheWeek), _repo.GetStoreHourByID(int.Parse(id)), _repo.GetAcceptedPayment(int.Parse(id)));

        return View(store);
    }

Thanks in advance.. 提前致谢..

Please do like below. 请像下面这样。

<span class="col-md-3">@Html.DisplayFor(model => payment.ImgPath)</span>

Instead of the above code please use the below one. 而不是上面的代码,请使用下面的代码。

<span class="col-md-3">
    <img src="~/Images/@payment.ImgPath" alt=""  />
</span>

If you have only filename in Model then you have to do this way using img tag utilizing its src attribute: 如果在Model中只有文件名,则必须使用img标签的src属性来执行此操作:

@foreach (StoreAcceptedPayment payment in Model.Item4)
{
   <img src="@Url.Content("~/"+payment.ImgPath)" />
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM