0

so i have images in my database and i want to show them in my view,this is my model:

public class SocialNetworkModel
{
    [Required]
    [DataType(DataType.Text)]
    public string titlePost { get; set; }

    [Required]
    [DataType(DataType.Text)]
    public string descriptionPost { get; set; }

    public byte[] picturePost { get; set; }
 }

this is my view :

foreach (var item in Model) {
<tr id="row-@item.cinOw">
    <td>
        @Html.DisplayFor(modelItem => item.titlePost)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.descriptionPost)
    </td>
    <td>
        //here i want to put my image
    </td>
</tr>
}

so please if someone has any idea i will be very grateful.

Mohammadov
  • 595
  • 3
  • 13
  • 34

1 Answers1

1

Create action in your controller as below

public FileContentResult displayImage(int productId) {
    SocialNetwork item = //Get your object
    if (item!= null) {
        return File(item.picturePost, "image Mime Type");
    } else {
    return null;
 }

}

And show this returned file in the view.

Guanxi
  • 3,103
  • 21
  • 38