2
參照此link,我使用MessagingToolkit.QRCode.dll創建了QR碼圖像。 如何使用myLayout在同一視圖中顯示已保存的圖像。
控制器代碼MVC4中的顯示圖像查看
[HttpPost]
public ActionResult GenerateExcelQR(string Command, FormCollection collection)
{
if (Command == "Excel")
{
// logic to generate Excel
}
else if(Command =="QRCode")
// qr code logic //
QRCodeEncoder encoder = new QRCodeEncoder();
Bitmap img = encoder.Encode(qrcode);
string path = Server.MapPath("/Images/QRCode.jpg");
img.Save(path, ImageFormat.Jpeg);
return base.File(path,"image/jpeg"); // Displays the QR image without my layout.
// return View(path,"image/jpeg"); // Returns an error specifying "Images\QRCode.jpg' or its master was not found or no view engine supports the searched locations."
}
如何在同一視圖的佈局顯示QR碼的圖像。
有什麼建議。
編輯 ImageModel.cs
public static class ImageModel
{
public static string Image(this HtmlHelper htmlHelper, string path, string alt)
{
var img = new TagBuilder("img");
img.MergeAttribute("src", path);
img.MergeAttribute("alt", alt);
return img.ToString(TagRenderMode.SelfClosing);
}
}
鑑於
@model IEnumerable<SampleECommerce.Models.CheckoutModel> // reference to 1st model to return values
@using SampleECommerce.Models; // for Imagemodel
我試過返回視圖(路徑,「image/jpeg」);在View中渲染圖層。它會拋出找不到圖像的錯誤。 – kk1076
@ kk1076,editied我的回答 –
如何使用這個Htmlhelper代碼。我在我的控制器中使用了這個,但它說@ Html.Imager錯過了程序集或引用。 – kk1076