I have an object of type IMAGE which holds image. I wanted to display the image in MVC view along with other controls. The way i can think of is to temporary store image on disk and set src of img control. I am sure there would be better way of doing this.
The easiest way to do this in my opinion would be to return a FileStreamResult
from your controller.
public FileResult GetImage()
{
string path = "c:\images\image.jpg";
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");
}
This is a simple implementation, but gives you a starting point for what you are attempting to do.
If you are interested in implementing @Giovanni's answer, then I have some code that may be helpful from a past answer I gave located here. The ImageHandler class is an example of what you would want to implement in Giovanni's case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With