2

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

1
  • Did you check the img src in your browser? First thing I'd fix would be putting quotes around the src attribute value. Commented May 2, 2017 at 8:08

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i update my answer just change src=@urlPath to src='@urlPath'. try this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.