Asp.Net Core Image Get From Database

Last Reply 14 days ago By dharmendr

Posted 28 days ago

Hi,

I am using .NET Core. I created image folder. and added database. But I wanna show image in table.

Controller 

 TProjects proje = new TProjects();
                if (resimyolu != null)
                {
                    proje.CatId = catid;
                    proje.Baslik = baslik;
                    proje.İcerik = icerik;
                    var path = Path.Combine(
                     Directory.GetCurrentDirectory(), "wwwroot/resimler", resimyolu.FileName);
                    var stream = new FileStream(path, FileMode.Create);
                    proje.ResimYolu = resimyolu.FileName;

                }

                port.TProjects.Add(proje);
                port.SaveChanges();

Index.cshtml

 

  @foreach (var item in Model)
                                    {
                                        <tbody>
                                            <tr class="odd gradeX">
                                                <td>@item.Id</td>
                                                <td>@item.Baslik</td>
                                                <td>@item.İcerik</td>
                                                <td><img src="~/resimler/@item.ResimYolu" width="150" height="150" /></td>

                                                <td>
                                                    <button class="btn btn-primary" data-toggle="modal" data-target=".@item.Id">
                                                        Düzenle
                                                    </button>
                                                </td>
                                            </tr>

                                        </tbody>
                                    }

 

You are viewing reply posted by: dharmendr 14 days ago.
Posted 14 days ago

Hi AliYilmaz,

AliYilmaz says:
<td><img src="~/resimler/@item.ResimYolu" width="150" height="150" /></td>

Replace the above code with below.

<td><img src="resimler/@item.ResimYolu" width="150" height="150" /></td>

If it will not resolve your issue refer below links.

https://stackoverflow.com/questions/41411287/loading-image-from-database-in-mvc-net-core

https://stackoverflow.com/questions/50461175/asp-net-core-2-0-retrieve-image-url