Ajax在ASP.NET MVC中上传
2024-09-30 15:02:42
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>
最新文章
- txt文本变成html
- SQL Server 深入解析索引存储(上)
- 分治法解决合并排序(c++和Java源代码)
- UIView与CALayer的区别
- 【linux】awk的使用
- 在安卓下使用python连接蓝牙串口模块(HC-06)
- Ch04 充满动作的控制器
- - (void)addAnimation:(CAAnimation *)anim forKey:(nullable NSString *)key; 方法浅析
- mySQL内存及虚拟内存优化设置
- KeePass使用心得
- Linux开发环境工具收集
- 《MySQL技术内幕》读书笔记
- 《Python数据可视化编程实战》
- java四种访问权限符
- jspm 简介
- web测试实践
- 如何安装docker-compose
- java---rce
- Hive 和 HBase区别
- Team Foundation Server (TFS) 2017 团队资源管理器
热门文章
- NEXYS 3开发板练手--USB UART(三)
- C++范围解析运算符::的使用
- python(21)实现多进程(1)
- Angularjs 源码
- 【linux】Shell脚本启动程序
- 【AUC】二分类模型的评价指标ROC Curve
- 利用jdbc连接池(利用jdni)
- 【C#/WPF】TextBlock/TextBox/Label编辑文字的问题
- ramdisk文件系统制作
- /dev/sdxx is apparently in use by the system; will not make a filesystem here! 解决方法