返回一個對象,像我有一個控制器,使圖像在蒼蠅和回報的觀點在ViewBag文本,從控制器
public partial class TextController : Controller
{
public virtual ActionResult Index(bool noisy = true)
{
//image stream
FileContentResult img;
using (var mem = new MemoryStream())
using (var bmp = new Bitmap(130, 30))
using (var gfx = Graphics.FromImage((Image)bmp))
{
gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
gfx.SmoothingMode = SmoothingMode.AntiAlias;
gfx.FillRectangle(Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height));
//add question
gfx.DrawString(text, new Font("Tahoma", 15), Brushes.Gray, 2, 3);
//render as Jpeg
bmp.Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);
img = File(mem.GetBuffer(), "image/Jpeg");
}
ViewBag.text = text;
return img;
}
} 我想返回一個圖像和ViewBag從控制器。 什麼是解決方案?如何做這項工作?
什麼?你能改說嗎? – gdoron
@gdoron我編輯的問題。 – user197508
這是控制器索引行動預計將返回HTML與IMG在它呢? – Igor