Mohadeseh
Mohadeseh

Reputation: 366

image not display in asp.net

I located my images in App_Data folder and image sub folder .and i wrote this code in view :

 @if (File.Exists(Server.MapPath("~/App_Data/" + item.Picture)))
 {
     <img  title="Click to view product detail"  [email protected]("~/App_Data/" + item.Picture) />
 }

item.Picture is : path and picture name sample : image/1.jpg. condition of if is true but image not show

Upvotes: 2

Views: 99

Answers (1)

Ashiquzzaman
Ashiquzzaman

Reputation: 5284

The App_Data folder is a special folder for database files and so on.Your images do definitely not belong into the App_Data subfolder. Put them into a folder like images (just outside App_Data folder) then Try This:

@{
    var filePath=Path.Combine(Server.MapPath(@"~/images/"),item.Picture);
    var urlPath= @"/images/"+item.Picture; //where like item.Picture=@"image/1.jpg"
}

@if (File.Exists(filePath))
{
    <img  title="Click to view product detail"  src='@urlPath'/>
}

Hopefully it's work for you.

Upvotes: 3

Related Questions