asp.net mvc显示图像而不使用数据库

时间:2012-10-13 01:46:58

标签: asp.net-mvc

我想在下一页显示我上传到服务器的图像和节点。

这是我的代码: “

public ActionResult Review(HttpPostedFileBase uploadfile)
        {

            string note = Request.Form["note"];
            string deliverytime = Request.Form["time"];
            HttpPostedFileBase imagetest = Request.Files["uploadfile"];
            System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(imagetest.InputStream);
            string imagestring = imagetest.ContentType.ToString();
            ViewBag.Mime = "image/jpeg";
Stream stream = uploadfile.InputStream;
                byte[] image = new byte[uploadfile.ContentLength];
                stream.Read(image, 0, uploadfile.ContentLength);
 ViewBag.Message = Convert.ToBase64String(image, Base64FormattingOptions.InsertLineBreaks);
                 ViewData["note"] = "user note:"+note;
               return PartialView();
}

” 和cshtml

@Html.Encode(ViewData["note"])<br />
<img src="data:@ViewBag.Mime;base64,@ViewBag.Message" />

图像无法在下一页显示。非常感谢你的帮助!

0 个答案:

没有答案