It is a common requirement where we need to create a controller that simply returns an image.
Following is one of the possible solutions for implementing the above functionality.
We need to add the following code on controller page
public ActionResult Image(string imageId)
{
try
{
string directory = Server.MapPath("/Image");
string imagePath = Path.Combine(directory , imageId + ".jpg");
return base.FileimagePath , "image/jpeg");
}
catch(Exception ex)
{
throw;
}
}
/Image : It is the path where images are located
id : It is the identifier of the image
The URL of the path is :
http://localhost/MyController/Image/MyImage
On accessing the above url the image with the requested identifier gets served.
0 Comment(s)