2013-05-05 99 views
0

,所以我有我的数据库中的图像,我想向他们展示在我看来,这是我的模型:如何从数据库显示图像到剃刀视图?

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; } 
} 

这是我的看法:

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

所以请有人有任何想法,我会非常感激。

+0

检查此问题http://stackoverflow.com/questions/9149430/displaying-image-from-db-in-razor-mvc3 – 2013-05-05 15:05:07

+0

感谢兄弟对我有用 – Mohammadov 2013-05-05 15:35:58

回答

1

建立在你的控制器动作如下

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

}

,并出示此返回的文件的视图。

+0

哦对不起,我没有看到上面的评论。这有解决方案。 – Guanxi 2013-05-05 15:22:24