在使用ASP.NET MVC时,如何保存图像并从SQL Server Image字段中显示它们?
非常感谢 尼克
答案 0 :(得分:2)
MvcFutures http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=18459项目有一个FileResult,它是一种ActionResult。您可以使用它将二进制流返回给浏览器。
答案 1 :(得分:0)
您也可以通过控制器操作完成此操作:
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();
}
}