Click here to Skip to main content
14,879,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I have some doubts in MVC3, I need to show several images from a local folder.

And now i retrive the image path from database to a array string in the controller.
and don't know wot to do next.?

I need to show these images in view from these array string in controller.

Please help me.



Thanks

Dileep
Posted

1 solution

Create a controller which read the imagepath from database and returns it as Image from your Controller

C#
public class ImageController : Controller
{
    public ActionResult ShowImage(int id)
    {
        // access your database and read the filepath based on id

        return new FilePathResult(pathFromDatabase, "image/jpeg");
    }

}

Then you can just add an img tag with the id of the picture in your database:
HTML
<img src="/Image/ShowImage/123" />

Where 123 is the value you'll need to find it in your database.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900