Follow by Email

How to show image from binary data in database in MVC3 razor?

In this tutorial i will explain that how can we show image in web page from binary data of database.

Get image from database in your controller....
        public ActionResult GetImage(int id)
            var imageData = ....get image from database in binary formate...
            return File( imageData, "image/jpg" );
                Create the action in your controller which will get the binary data of the image from database in the variable.
                Return the File to the view with binary data & image file type.

Call the action from the view
<img src="@Url.Action("GetImage""ImageLoader"
new { id = @Model.Id })" name="logoFile"/>

                Now we need to call the action from the view. Which can be done as shown above.
Where :
GetImage : Action Name. (here put your action name)
ImageLoader : Controller Name. (here put your controller name)
@Model.Id : id of the data for which you want to show the image (here put id for which you want to show the image )


Surya Pandey said...

its really very helpful and worked for me

ANIL BABU Mandla said...

How to save, update and delete image to database using MVC
How to Store Images database and also perform all curd operations using ASP.NET MVC
I am performing normal data to store in database at the time use upload control to store the images to database how to do?
I am new to Mvc
Gove me one simple example on this complete code for that

please help me

asad rauf said...

public ActionResult GetImage(int id)
var imageData = (....get image from database in binary formate...)
what i write hare in breket
return File( imageData, "image/jpg" );

Post a Comment