htcszgn
htcszgn

Reputation: 3

How to display image from path in Asp.Net MVC 5

DosyaYolu.cshtml

@{
  Layout = null; 
  string dosyaYolu = Server.MapPath("~/Views/Home/Adsiz.jpg");
 }

<img src="@dosyaYolu" /> 

I could not display image from dosyaYolu path.What will I need to do?

Upvotes: 0

Views: 3988

Answers (1)

Aravindan
Aravindan

Reputation: 855

Please just the pass the URL as itself. Because Server.MapPath will change the URL which can understandable by machine not by the browser.

It will be useful when the image file is inside of the your application.

Just pass the URL as

 @{
    Layout = null; 
    var dosyaYolu = @Url.Content("~/Views/Home/Adsiz.jpg");
  }

<img src="@dosyaYolu" />

Upvotes: 1

Related Questions