下载异步上传插件AjaxFileUploader,下载地址:
解压,保存在 asp.net mvc项目的一个文件夹下,如下图:
public ActionResult View3()
public ActionResult View3(HttpPostedFileBase file)
return Content("没有文件!", "text/plain");
var fileName = Path.Combine(Request.MapPath("~/UploadFiles"), Path.GetFileName(file.FileName));
return Content("上传成功!", "text/plain");
return Content("上传异常 !", "text/plain");
<meta name="viewport" content="width=device-width" />
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/ajaxfileupload/jquery.js"></script>
<script src="~/ajaxfileupload/ajaxfileupload.js"></script>
<script type="text/javascript">
function ajaxFileUploads() {
$("#loading").ajaxStart(function () {
.ajaxComplete(function () {
url: '/Test/View3',//后台处理的action
fileElementId: 'file',//上传的控件名
success: function (data, status) {
error: function (data, status, e) {
$("#mydiv").html( data + " " + e);
<input type="file" id="file" name="file" />
<img src="../ajaxfileupload/loading.gif" width="20px" height="20px" id="loading" style="display: none;">
<span id="mydiv" style="color: green;"></span>
<input type="button" value="上传" ajaxFileUploads();">