【问题标题】:asp.net mvc saving and displaying images in dbasp.net mvc 在数据库中保存和显示图像
【发布时间】:2010-07-25 12:15:14
【问题描述】:

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

非常感谢 尼克

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    MvcFutures http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=18459 项目有一个 FileResult,它是 ActionResult 的一种类型。您可能可以使用它向浏览器返回二进制流。

    【讨论】:

      【解决方案2】:

      您也可以通过控制器操作自己简单地执行此操作:

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

      【讨论】:

        猜你喜欢
        • 2018-01-24
        • 2012-03-25
        • 1970-01-01
        • 2016-07-27
        • 2013-09-21
        • 2010-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多