Asp.net mvc asp.net mvc在数据库中保存和显示图像

Asp.net mvc asp.net mvc在数据库中保存和显示图像,asp.net-mvc,Asp.net Mvc,使用ASP.NET MVC时,如何保存图像并从SQL Server图像字段显示它们 非常感谢 NickMVC未来项目有一个FileResult,它是ActionResult的一种类型。您可能可以使用它将二进制流返回到浏览器。您也可以通过控制器操作轻松完成此操作: public void RenderImage(int imageId) { // TODO: Replace this with your API to get the image blob data. byte[]

使用ASP.NET MVC时,如何保存图像并从SQL Server图像字段显示它们

非常感谢
Nick

MVC未来项目有一个FileResult,它是ActionResult的一种类型。您可能可以使用它将二进制流返回到浏览器。

您也可以通过控制器操作轻松完成此操作:

public void RenderImage(int imageId)
{
    // TODO: Replace this with your API to get the image blob data.
    byte[] data = this.repo.GetImageData(imageId);

    if (data != null)
    {
        // This assumes you're storing JPEG data
        Response.ContentType = "image/jpeg";
        Response.Expires = 0;
        Response.Buffer = true;
        Response.Clear();
        Response.BinaryWrite(data);
    }
    else
    {
        this.ControllerContext.HttpContext.ApplicationInstance.CompleteRequest();
    }
}