图片预览弹出框
<!--弹出框-->
<!--
作者:152645239@qq.com
时间:2016-07-06
描述:图片预览弹出框
-->
<div id="PicViewdlg" class="easyui-dialog" title="@BaseRes.SPS_TIT_005" style="width:600px;height:500px;padding:5px;" data-options="
toolbar: '#dlg-toolbar',
buttons: '#dlg-buttons',
closed:true
">
<div style="width: 650px; height: 450px; ">
<img id="picViewss" />
</div>
<a class="easyui-linkbutton width80" data-options="iconCls:'icon-ok'" href="javascript:void(0)" οnclick="$('#PicViewdlg').dialog('close');">关闭</a>
</div>
图片预览js方法,需要传入路径
//预览服务器图片
//FilePath 文件路径,服务器可以访问的路径
function picView(FilePath) {
$.ajax({
type: 'POST',
url: "/PackagingInformation/PicNowView?" + "fileUpd=" + encodeURIComponent(FilePath),
//data: pars,
cache: false,
async: false,
dataType: "json",
success: function (packJson) {
if (packJson.result == 1) {
var img = document.getElementById("picViewss");
//图片路径设置为读取的图片
img.src = packJson.Content.Content;
$('#PicViewdlg').dialog({
title: '预览',
width: 600,
height: 500,
closed: false,
cache: false,
modal: true
});
$('#PicViewdlg').window('center');
$('#PicViewdlg').dialog('open');
}
else {
$.messager.alert('@BaseRes.COM_CTL_NOTICE', packJson.Msg);
}
}
});
};
Controller方法
/// <summary>
/// 查看图片,返回图片数据
/// </summary>
/// <param name="fileUpd"></param>
/// <returns></returns>
public JsonResult PicNowView(string fileUpd)
{
byte[] infbytes = new byte[0];
try
{
FileStream fs = new FileStream(fileUpd, FileMode.Open, FileAccess.Read);
infbytes = new byte[(int)fs.Length];
fs.Read(infbytes, 0, infbytes.Length);
fs.Close();
var _Content= Content("data:image/png;base64," + Convert.ToBase64String(infbytes) + "", "text/html");
return Json(new { result = 1,Content=_Content, Msg = "获取成功" });//"添加失败!"
}
catch (Exception)
{
return Json(new { result = 0, Msg ="预览失败,文件不存在"});//"添加失败!"
}
}