原本的图片 上传感觉不是很好 不是我想要的
1.0改造 第一步 前端 Common.js
添加一个上传 函数
function uploadImage(objj) {
var da = new FormData();
da.append('file', objj.files[0]);
$.ajax({
contentType: false,
processData: false,
type: 'POST',
url: '/Annex/up.html',
data: da,
});
}
2.0 修改生成前端页面
UIFrameFactory.cs 文件下 第 1655行开始
改成 向下面一样
case ControlTypeEnum.ImageUpload: //图片上传控件
{
#region 图片上传控件
if (!isSearchForm)
{
sb.AppendFormat("<input id=\"{0}\" type=\"file\" onchange=\"uploadImage(this)\" />", sysField.Name/*, value.ObjToStr()*/);
}
#endregion
}
break;
3.0 修改图片处理控制器 AnnexController
增加 一个up 的action 将图片上传 并保存到Session中
以方便后面调用
public ActionResult up(HttpPostedFileBase file)
{
if (file == null)
{
return Json(new { Success = false, Message = "请选择上传文件!" });
}
if (_Request == null) _Request = Request;
string message = string.Empty;
try
{
HttpPostedFileBase filee = Request.Files["file"];
byte[] img = new byte[filee.ContentLength];
filee.InputStream.Read(img, 0, file.ContentLength);
//保存文件
string str = WebHelper.Base64EncodeBytes(img);
Session["iamge"] = str;
message = “临时图片保存成功!”;
return Json(new { Success = string.IsNullOrEmpty(message), Message = message}, "text/plain");
}
catch (Exception ex)
{
message = string.Format("图片上传失败,原因:{0}", ex.Message);
return Json(new { Success = false, Message = message }, "text/plain");
}
}
未完待续