このリンクを参考に、 MessagingToolkit.QRCode.dll を使って QR コード画像を作成しました。保存した画像をmyLayoutで同じビューに表示する方法。
コントローラーコード
[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."
}
レイアウトと同じビューに QRCode 画像を表示する方法。
助言がありますか。
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