GHSpro文件上传
上传
上传方式的选择
采用iframe 的表单上传
ajaxfileupload
<div id="step-2" class="step-pane" style="margin:5px">
<div style="height:40px;line-height:33px;text-align:right">
<div class="btn-group">
<a id="lr-add-second" class="btn btn-default"><i class="fa fa-plus"></i> 新增</a>
<a id="lr-edit-second" class="btn btn-default"><i class="fa fa-pencil-square-o"></i> 编辑</a>
<a id="lr-delete-second" class="btn btn-default"><i class="fa fa-trash-o"></i> 删除</a>
</div>
</div>
<table id="gridTable"></table>
</div>
$(function () {
$("#submitId").on("click", function () {
alert("1")
///GetFileEx
var filePath = $("#file1").val();
alert(filePath)
//var fileEx = GetFileEx(filePath);
var fileNO = "@Run.Util.CommonHelper.CreateNo()";
if (filePath != null && filePath.length > 0)
{
$.ajaxFileUpload({
url: "../../Helper/FileUpload/UpModelWordFile?fileNO=" + fileNO,
secureuri: false,//是否启用安全机制
fileElementId: 'file1',//file的id
dataType: 'application/json',//返回的类型
success: function (data) {//调用成功时怎么处理
alert(JSON.stringify(data));
},
error: function (e) { alert(JSON.stringify(e)) }
});
}
else
{
alert("请先选择文件!");
}
});
});
后台代码
[HttpPost]
public ActionResult UpModelWordFile(string fileNO, HttpPostedFileBase file1)
{
// string templatePath = Server.MapPath("/") + "Resource/WordTemplate/moban/";
if (file1.ContentLength > 0)
{
var fileName = Path.GetFileName(file1.FileName);
var path = Path.Combine(Server.MapPath("~/Resource/WordTemplate/moban"), (fileNO + fileName));
file1.SaveAs(path);
}
return new ContentResult();
}