uploadifive是一个款基于H5的上传文件的插件。优点是,可以在PC端,也可以在手机上进行操作。缺点是,IE9以下的兼容性不好。

View:

 <!DOCTYPE html>

 <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Content/uploadifive/jquery.uploadifive.min.js"></script>
<link href="~/Content/uploadifive/uploadifive.css" rel="stylesheet" />
</head>
<body>
<div id="queue"></div>
<input type="file" id="file_upload" name="file_upload" /> <script>
$(function () {
$('#file_upload').uploadifive({
'auto': true,
'queueID': 'queue',
'buttonText': '上传文件',
'uploadScript': '/File/UploadFile',
'onUploadComplete': function (file, data) {
if (data) {
alert('上传成功')
} else {
alert('上传失败' + rspdesc);
}
}
});
});
</script>
</body>
</html>

Controller

  /// <summary>
/// 上传文件
/// </summary>
public ActionResult UploadFile(HttpPostedFileBase fileData)
{
if (fileData.ContentLength > )
{
string fileExt = Path.GetExtension(fileData.FileName);
string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmssff") + fileExt;
string savePath = Server.MapPath("~/Upload/"+ fileName);
fileData.SaveAs(savePath);
return Content("ok");
}
else
{
return null;
}
}
05-11 23:02