C# MVC4将图像文件从SQL Server表检索到html图像

C# MVC4将图像文件从SQL Server表检索到html图像,c#,sql-server,jquery,asp.net-mvc-4,razor,C#,Sql Server,Jquery,Asp.net Mvc 4,Razor,我正在尝试在MVC4 web应用程序上创建用户配置文件页面 在userprofile页面上有一个图像,以便在profile页面上显示实际照片 问题2:有人能提出更好的替代方案建议/示例/指针来实现与Jquery/Ajax/javascript相同的功能吗 提前感谢您可以使用文件结果将二进制数据发送到响应 byte[] barrImg = usr.GetProfilePhoto(id); 你可以把它当作 public FileResult GetProfileImage(int id) {

我正在尝试在MVC4 web应用程序上创建用户配置文件页面

在userprofile页面上有一个图像
,以便在profile页面上显示实际照片

问题2:有人能提出更好的替代方案建议/示例/指针来实现与Jquery/Ajax/javascript相同的功能吗


提前感谢

您可以使用
文件结果
将二进制数据发送到响应

byte[] barrImg = usr.GetProfilePhoto(id);
你可以把它当作

public FileResult GetProfileImage(int id)
{
    var usr = new Whatever();
    byte[] barrImg = usr.GetProfilePhoto(id);
    return File(barrImg, "image/png");
}

public FileResult GetProfileImage(int id)
{
    var usr = new Whatever();
    byte[] barrImg = usr.GetProfilePhoto(id);
    return File(barrImg, "image/png");
}
 <img src="@Url.Action("GetProfileImage", "Controller", new { id = 5})"