HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace ajaxUpload.Controllers
{
public class HomeController : Controller
{
[HttpPost]
public JsonResult Upload()
{
var uploadedFile = Request.Files[0] as HttpPostedFileBase;
return Json(uploadedFile.FileName);
} public ActionResult Index()
{
return View();
} }
}

Index.cshtml@   

ViewBag.Title = "Home Page"}

<div class="jumbotron">
<h1>Ajax在ASP.NET MVC中上传</h1>
</div>
<div class="row">
<div id="main">
<h1>上传您的图片</h1>
<form id="uploadfrm" method="post" enctype="multipart/form-data" action="/home/upload">
<input type="file" name="images" id="images" />
</form>
<div id="response"></div>
<ul id="image-list"></ul>
</div>
<button onclick="Upload();">上传</button>
</div> <script>
function Upload() {
var form = document.getElementById('uploadfrm');
var formData = new FormData(form); // 这里如何把form的数据上传
$.ajax({
url: "/home/upload",
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function (res) {
document.getElementById("response").innerHTML = res;
}
});
}
</script>

最新文章

  1. txt文本变成html
  2. SQL Server 深入解析索引存储(上)
  3. 分治法解决合并排序(c++和Java源代码)
  4. UIView与CALayer的区别
  5. 【linux】awk的使用
  6. 在安卓下使用python连接蓝牙串口模块(HC-06)
  7. Ch04 充满动作的控制器
  8. - (void)addAnimation:(CAAnimation *)anim forKey:(nullable NSString *)key; 方法浅析
  9. mySQL内存及虚拟内存优化设置
  10. KeePass使用心得
  11. Linux开发环境工具收集
  12. 《MySQL技术内幕》读书笔记
  13. 《Python数据可视化编程实战》
  14. java四种访问权限符
  15. jspm 简介
  16. web测试实践
  17. 如何安装docker-compose
  18. java---rce
  19. Hive 和 HBase区别
  20. Team Foundation Server (TFS) 2017 团队资源管理器

热门文章

  1. NEXYS 3开发板练手--USB UART(三)
  2. C++范围解析运算符::的使用
  3. python(21)实现多进程(1)
  4. Angularjs 源码
  5. 【linux】Shell脚本启动程序
  6. 【AUC】二分类模型的评价指标ROC Curve
  7. 利用jdbc连接池(利用jdni)
  8. 【C#/WPF】TextBlock/TextBox/Label编辑文字的问题
  9. ramdisk文件系统制作
  10. /dev/sdxx is apparently in use by the system; will not make a filesystem here! 解决方法