首页 > 代码库 > 下载图片

下载图片

 public ActionResult Download(string url)
        {
            Response.AddHeader("content-type", "application/application/x-msdownload");
            Response.AddHeader("Content-Disposition", "attachment;filename=" + url.Split(/).Last());
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream resStream = response.GetResponseStream();
            return File(resStream, response.ContentType);
        }
  @Html.ActionLink("下载", "Download", new { url = "http://h.hiphotos.baidu.com/baike/s%3D220/sign=eb8c4e58a2cc7cd9fe2d33db09002104/d009b3de9c82d1588b9c0c04810a19d8bc3e426c.jpg" })

 

下载图片