参考此链接,我使用 MessagingToolkit.QRCode.dll 创建了一个二维码图像。如何在与 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