【发布时间】:2010-07-25 12:15:14
【问题描述】:
在使用 ASP.NET MVC 时,如何保存图像并从 SQL Server 图像字段显示它们?
非常感谢 尼克
【问题讨论】:
标签: asp.net-mvc
在使用 ASP.NET MVC 时,如何保存图像并从 SQL Server 图像字段显示它们?
非常感谢 尼克
【问题讨论】:
标签: asp.net-mvc
MvcFutures http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=18459 项目有一个 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();
}
}
【讨论】: