Pooja
Pooja

Reputation: 495

how to display images from local folder to view using mvc

I am using MVC. i need to upload the image and display it in same page. i have uploaded the image and store the image in local folder. how to display the images from local folder file using mvc

Upvotes: 0

Views: 2746

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

The best way is to create an action that will load the file from the folder and return it.

Use FileContentResult:

public FileContentResult Display(string filename) {
   byte[] byteArray = GetImageFromDisk(filename);
   return new FileContentResult(byteArray, "image/jpeg");
}

The above is a very simplistic sample to get you going.

Upvotes: 2

Related Questions