mvc下返回一个二维码显示?
本帖最后由 a102470 于 2013-06-27 11:40:32 编辑
使用的是thoughtworks.QRCode.dll来生成二维码的,代码如下:[HttpPost]
public ActionResult GetImg()
{
if (Request.Params["chl"] == null) { return null; }
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
try
{
int scale = Convert.ToInt16(Request.Params["size"].ToString());
qrCodeEncoder.QRCodeScale = scale;
}
catch { }
String data = Request.Params["chl"].ToString();
MemoryStream ms = new MemoryStream();
System.Drawing.Image myimg = qrCodeEncoder.Encode(data, System.Text.Encoding.UTF8); //kedee 增加utf-8编码,可支持中文汉字
myimg.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
myimg.Dispose();
return File(ms.ToArray(), "image/jpeg");
}
function get(){
var url = "../../AMSBasicInfo/GetImg";
var tt = {
"chl":123,
"size": 4
};
$.post(url, tt})
}
要显示的区域:
<div id="DR" class="easyui-window" data-options="iconCls:'icon-save',modal:true,autoCenter:true" style="width:340px;height:320px;padding: 5px;" closed="true">