.NET MVC Dropzone 上传图片
在nuget控制台输入:Install-Package dropzone
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Scripts/dropzone/dropzone.min.css" rel="stylesheet" />
<script src="~/Scripts/dropzone/dropzone.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
</head>
<body>
<div class="container">
<header>
<div class="row">
<div class="col-md-9 text-right"></div>
</div>
</header>
<div class="row main" style="min-height:500px">
<div class="col-md-12">
<div class="row" style="margin-top:30px;">
<div class="col-md-3 col-xs-12 col-md-offset-3">
@*<form id="mydropzone" action="/sss/upload" class="dropzone"></form>*@
<div id="mydropzone" class="dropzone"></div>
</div>
</div>
</div>
</div>
<footer>
</footer>
</div>
<script>
var myDropzone = new Dropzone("div#mydropzone", {
url: "@Url.Action("update","controller")",
paramName: "file",
maxFilesize: 100, // MB
maxFiles: 5,
acceptedFiles: ".jpg,.png,.gif",
success: function (data) {
alert(data);
},
dictDefaultMessage: "点击上传图片",
dictInvalidInputType: "请选择格式为jpg,png,gif格式的图片",
addRemoveLinks: true,
dictRemoveFile: "移 除",
init: function () {
this.on("removedfile", function (file) {
debugger;
$.ajax({
type:"post",
url:"/sss/delete",
data:JSON.stringify({ id: file.name }),
contentType:"application/json;charset=utf-8",
success: function (data) {
if (data > 1)
{
alert("删除成功!!");
}
}
});
});
}
});
</script>
</body>
</html>
public class sssController : Controller
{ public string path;
// GET: sss
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult upload() {
HttpFileCollectionBase coll = Request.Files;
string fileName = "";
string fileExtension = "";
string filePath = ""; foreach (string item in coll)
{
HttpPostedFileBase file = Request.Files[item];
if (file != null && file.ContentLength > 0)
{
fileName = file.FileName;
fileExtension = Path.GetExtension(fileName);
filePath =Server.MapPath("/Content/photo/")+fileName;
path = filePath;
file.SaveAs(filePath);
}
}
return Json("ok");
}
[HttpPost]
public ActionResult delete(string id)
{
string filePath = Path.Combine(Server.MapPath("/Content/photo"), id);
int res = 0;
if (System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
res = 10;
}
return Json(res); }
}
.NET MVC Dropzone 上传图片的更多相关文章
- spring mvc 的上传图片是怎么实现的?
spring mvc 的上传图片是怎么实现的? 导入jar包,commons-io.jar 及 commons-fileupload.jar 在springmvc的配置文件中配置Mutipart解析器 ...
- mvc实现上传图片(上传和预览)webuploader
笔者看到mvc最近比较流行,而很多使用一些比较旧的的方法上传图片,再次安利一下百度的webuploader控件吧 webuploader第一步要先下载一些插件这点可以在webuploader官网上下载 ...
- ASP.NET MVC 4 - 上传图片到数据库
这里演示如何在MVC WEB应用程序如何上传图片到数据库以及如何在WEB页面上显示图片.数据库表对应整个Model类,不单图片数据一个字段,我们从数据表的定义开始: CREATE TABLE [dbo ...
- MVC异步上传图片到本地/服务器
这两天朋友问我,有没有异步上传图片到本地/服务器这种demo,他有用, 我就想,好吧, 那刚好周末了,整理一套出来. 主要用到的是jquery uploadify 这个juqery的插件 ,可以无刷新 ...
- 使用Dropzone上传图片及回显演示样例
一.图片上传所涉及到的问题 1.HTML页面中引入这么一段代码 <div class="row"> <div class="col-md-12" ...
- MVC ajaxSubmit上传图片
注意事项: 1.提交form,必须引用jquery.form.min.js 2.不要使用mvc自带的Ajax.Form() 1.页面cshtml <form name="frmInpu ...
- jquery.uploadify+spring mvc实现上传图片
一.前端页面 1.下载jquery.uploadify 去uploadify官网(http://www.uploadify.com/download/)下载压缩包,解压后放在如下路径: 2.html结 ...
- MVC实现上传图片的方法
Form提交时,须注意form需要添加属性enctype="multipart/form-data",否则Request.Files.Count=0,无法上传图片. cshtml代 ...
- mvc中上传图片到指定文件夹中
前台: @using (Html.BeginForm("AddImg", "UpFileImg", FormMethod.Post, new { enctype ...
随机推荐
- Hibernate中解决No Hibernate Session bound to thread问题
引用:忘了 首先是getCurrentSession()与openSession()的区别: 1.getCurrentSession()与openSession()的区别? * 采用getCurren ...
- ubuntu下安装 nginx + php + memcached + mariadb
一,apt-get 安装 1,安装nginx sudo apt-get install nginx 所有的配置文件都在/etc/nginx下,虚拟主机配置在/etc/nginx/sites-avail ...
- 把pcl的VTK显示融合到MFC(代码找原作者)
转自PCL中国,原文链接:http://www.pclcn.org/bbs/forum.php?mod=viewthread&tid=223&extra=page%3D1 本人做了少量 ...
- HttpSampler进行模拟webservice接口
webservice接口,使用HttpSampler进行模拟,注意点说明: 1. 2. 3. 4. 如果没有头信息,soap1.0的版本会返回错误body,如下, PS:soap1.2存在细微差别
- javaEE_maven_struts2_tomcat_first
1 .eclipse中新建项目
- 前端自动化构建yeoman
前端自动化可分为: yo(脚手架工具).grunt(构建工具).bower(包管理器). OMAN的特性 http://yeoman.io/learning/ 闪电般的初始化:项目开始阶段,可以基 ...
- 当使用junit4 对spring框架中controller/service/mapper各层进行测试时,需要添加的配置
@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations = {&quo ...
- C# html代码生成word
首先引入 Microsoft.Office.Interop.Word 其次要先说一下,把一大段html代码直接变成word文件,只能生成doc文件,docx文件应该是不行的 首先我们用IO生成一个do ...
- Day 10 函数
函数 1.什么是函数? 函数就是具备某一功能的工具,事先将工具准备好就是函数的定义,遇到应用场景拿来就用就是函数的调用 2.为何用函数? 如果不使用函数,写程序会遇到这三个问题 1.程序冗长 2.程序 ...
- Python笔记17---------魔法方法
魔法方法也为特殊方法,即用两个下划线形成的(__方法__).自己定义的方法最好不要采用这种方式,因为这些方法会在一些特殊的情况下直接被调用. 1.第一个魔法方法:类中常用的__init__()方法:相 ...