前端代码:
上传附件(如支付凭证等)
<input type="file" name="fileUpload" id="fileUpload" />
<ul id="imgPanle" style=" 300px"></ul>
<script type="text/javascript">
$(document).ready(function() {
$("#fileUpload").change(function() {
var formData = new FormData(); // FormData 对象
formData.append("fileUpload", document.getElementById("fileUpload").files[0]); // 文件对象
$.ajax({
type: 'post',
url: “/Attachment” //后台方法的路径
data: formData,
cache: false,
processData: false,
contentType: false
}).success(function (tempdata) {
alert(data);
}).error(function () {
alert("上传失败");
});
});
});
</script>
asp.net
后端代码
/// <summary>
/// 上传附件
/// </summary>
/// <param Name="file"></param>
/// <param Name="OrderID"></param>
/// <returns></returns>
public ActionResult Attachment(HttpPostedFileBase fileUpload, string OrderID)
{
//文件名
var Name = System.IO.Path.GetFileName(fileUpload.FileName);
System.IO.Stream str;
int strLen;
str = fileUpload.InputStream;
strLen = Convert.ToInt32(str.Length);
byte[] strArr = new byte[strLen];
str.Read(strArr, 0, strLen);
str.Close();
return Json(new{result=”OK”});
}