public class UpLoadFileController : Controller
{
//
// GET: /UpLoadFile/ public ActionResult Index()
{
return View();
} /// <summary>
/// 上传文件【上传文件到UploadFiles文件夹】
/// </summary>
/// <param name="fileData"></param>
/// <param name="Id"></param>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Post)]
public ContentResult UpLoadFile(HttpPostedFileBase fileData, String Id)
{
ControllerContext.HttpContext.Request.ContentEncoding = Encoding.UTF8;
ControllerContext.HttpContext.Response.ContentEncoding = Encoding.UTF8;
ControllerContext.HttpContext.Response.Charset = "UTP-8"; string filePath = Server.MapPath(@"/UploadFiles");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
if (fileData != null)
{
string fileSaveName = Path.Combine(filePath, fileData.FileName);
fileData.SaveAs(fileSaveName);
return Content("成功");
}
return Content("失败");
} /// <summary>
/// 获取文件【下载】
/// </summary>
/// <param name="id">文件名</param>
/// <returns></returns>
public FilePathResult GetFile(string id)
{
if (string.IsNullOrEmpty(id))
{
return null;
}
id = id.Replace("__", ".");
string path = "UploadFiles";
string filePath = Server.MapPath(@"/" + path);
string fileSaveName = Path.Combine(filePath, id);
return File(fileSaveName, "image/*", id);
} }

Index.cshtml

@{
ViewBag.Title = "上传文件";
}
<script src="~/Content/uploadify/jquery.uploadify.js?ver=@DateTime.Now.Ticks"></script>
<link href="~/Content/uploadify/uploadify.css" rel="stylesheet" /> @*上传文件*@
<div>
<input class="easyui-validatebox" type="hidden" id="Attachment_GUID" name="Attachment_GUID" />
<input id="file_upload" name="file_upload" type="file" >
@* <a href="javascript:void(0)" class="easyui-linkbutton" id="btnUpload" data-options="plain:true,iconCls:'icon-save'"
onclick="javascript: $('#file_upload').uploadify('upload', '*')">上传</a>
<a href="javascript:void(0)" class="easyui-linkbutton" id="btnCancelUpload" data-options="plain:true,iconCls:'icon-cancel'"
onclick="javascript: $('#file_upload').uploadify('cancel', '*')">取消</a>
<div id="fileQueue" class="fileQueue"></div>*@
<a href="javascript:void(0)" class="easyui-linkbutton" id="btnBrowse" >浏览</a>
<div id="div_files">
<a id="downFile" href="#">下载文件</a>
<img id="uploadImg" src=""/>
</div>
<br /> </div> @*弹出层*@
@Html.Partial("Contact") <script> $(function () {
$("#btnBrowse").click(function () {
PopLayout.Pop($("#uploadImg").attr("src"));
}); $("#file_upload").uploadify({
height: 30,
width: 120,
buttonText: "选择",
multi: false,
swf: '/Content/uploadify/uploadify.swf',
uploader: '@Url.Action("UpLoadFile","UpLoadFile")',
onFallback: function () {
alert("不支持flash");
},
onUploadError: function (file, errorCode, errorMsg, errorString) {
alert("文件" + file.name + "上传失败: " + errorString);
},
onUploadSuccess: function (file, data, response) {
if (true) {
//alert(file.name);
var id = file.name.replace(".", "__");;
$("#downFile").attr("href", "/UpLoadFile/GetFile/" + id);
$("#uploadImg").attr("src", "/UploadFiles/" + file.name);
}
//alert("文件" + file.name + "上传成功:" + data);
}
});
}); </script>

@Html.Partial("Contact")  嵌入Contact.cshtml文件

请看上篇文章,弹出层:http://www.cnblogs.com/liujinwu-11/p/4334568.html

mvc上传,下载,浏览文件功能(用uploadify插件)的更多相关文章

  1. asp.net mvc上传头像加剪裁功能

    原文:asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jqu ...

  2. mvc上传头像加剪裁功能

    asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jquery ...

  3. SpringMVC文件上传下载(单文件、多文件)

    前言 大家好,我是bigsai,今天我们学习Springmvc的文件上传下载. 文件上传和下载是互联网web应用非常重要的组成部分,它是信息交互传输的重要渠道之一.你可能经常在网页上传下载文件,你可能 ...

  4. Xshell5下利用sftp上传下载传输文件

    sftp是Secure File Transfer Protocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp 与 ftp 有着几乎一样的语法和功能.SFTP 为 SSH ...

  5. Spring框架学习(8)spring mvc上传下载

    内容源自:spring mvc上传下载 如下示例: 页面: web.xml: <?xml version="1.0" encoding="UTF-8"?& ...

  6. 使用ftp软件上传下载php文件时换行丢失bug

    正 文:   在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下notepad++编辑器写好的php文件,在使用ftp上传到linux服务器后,php文件的换行符全部丢失了, ...

  7. 使用ftp软件上传下载php文件时换行丢失bug(全部变为一行)

    文章来源:http://www.piaoyi.org/computer/ftp-php-r-n-bug.html 正 文: 在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下 ...

  8. java FTP 上传下载删除文件

    在JAVA程序中,经常需要和FTP打交道,比如向FTP服务器上传文件.下载文件,本文简单介绍如何利用jakarta commons中的FTPClient(在commons-net包中)实现上传下载文件 ...

  9. ****使用ftp软件上传下载php文件时换行符丢失bug

    在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下notepad++编辑器写好的php文件,在使用ftp上传到linux服务器后,php文件的换行符全部丢失了,导致php文件 ...

  10. Spring Boot2(十四):单文件上传/下载,文件批量上传

    文件上传和下载在项目中经常用到,这里主要学习SpringBoot完成单个文件上传/下载,批量文件上传的场景应用.结合mysql数据库.jpa数据层操作.thymeleaf页面模板. 一.准备 添加ma ...

随机推荐

  1. ARM 之LCD和LCD控制器

    既然提到 了LCD那么我们首先必须要了解的就是他的种类,CD(liquid crystal  display), 即液晶显示器,是这一种采用了液晶控制透光度计数来实现色彩的显示器,他与传统的CRT显示 ...

  2. DOM commend

    var comment = document.createComment("commend content"); var elem = document.getElementByI ...

  3. QT下实现对Linux Shell调用的几种方法

    使用QProcess QThread ============================================ #include <QProcess>int main(){ ...

  4. bzoj 1196

    http://www.lydsy.com/JudgeOnline/problem.php?id=1196 二分+并查集 一共有2*M条路径,我们首先将这2*M条路径按费用排序. 然后二分最大费用的公路 ...

  5. cocos2dx lua 加密

    cocos2dx-lua项目发布时,为了保护lua源码,需要对lua进行加密.通常分为两种方式:加密文件和编译为字节码. 1.加密文件 前提是你不用luajit,而使用lua.这样这种方法是真正加密, ...

  6. 屏蔽掉返回键,menu键,Home键

    public class LockActivity extends Activity{ private static final int FLAG_HOMEKEY_DISPATCHED = 0x800 ...

  7. World Wind Java开发之十五——载入三维模型

    之前的一篇博客是关于载入粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能载入纹理的问题,一直没呢解决 ...

  8. android调试系列--使用ida pro调试so

    1.工具介绍 IDA pro: 反汇编神器,可静态分析和动态调试. 模拟机或者真机:运行要调试的程序. 样本:阿里安全挑战赛第二题:http://pan.baidu.com/s/1eS9EXIM 2. ...

  9. 获取sqlserver数据库中所有库、表、字段名的方法

    获取sqlserver数据库中所有库.表.字段名的方法 2009年03月12日 星期四 下午 12:51 1.获取所有数据库名: SELECT Name FROM Master..SysDatabas ...

  10. JavaScript 函数方法 - bind()

    Function.prototype.bind() ECMAScript5中新增的方法,但是在ECMAScript3可以通过模仿实现其方法作用 作用: bind() 方法会创建一个新函数,当这个新函数 ...