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. OCR中的倾斜矫正

    电面中被问到了做的LPR,简单的介绍了下后又问到了关于如何矫正倾斜角的问题.答得比较含糊,所以今天来补充一下. 倾斜矫正的方法有很多种,包括基于Hough变换的矫正,基于字符投影的倾角矫正,常规线性角 ...

  2. 第8章 Android数据存储与IO——File存储

    openFileOutput/openFileInput 这是android自带的两种解决方案.

  3. absolute vs fixed

    <!DOCTYPE html> <html> <head> <title>absolute和fixed的区别</title> <sty ...

  4. Light OJ 1314 Names for Babies

    http://www.lightoj.com/volume_showproblem.php?problem=1314 题意:给定一个串和p,q,求长度在p到q之间的子串有几种 思路:后缀数组,对于每个 ...

  5. UNIX网络编程--IPV4 IPV6 ICMPV4 ICMPV6

    一.IPV4首部 IP层提东无连接不可靠的数据报递送服务.它会尽力把IP数据报递送到指定的目的地,然而并不保证他们一定到达,也不保证他们的到达顺序与发送顺序一致,还不保证每个IP数据报只到达一次.任何 ...

  6. [转]ubuntu14.04安装好用的google拼音输入法

    原文网址:http://jingyan.baidu.com/article/219f4bf7d4a183de442d38f2.html 装了ubuntu14.04后感觉自带的拼音输入法不好用的有没有, ...

  7. LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别

    LIBRARY_PATH和LD_LIBRARY_PATH是Linux下的两个环境变量,二者的含义和作用分别如下: LIBRARY_PATH环境变量用于在程序编译期间查找动态链接库时指定查找共享库的路径 ...

  8. jQuery旋转插件jqueryrotate 图片旋转

    "jquery.rotate.min.js"是jQuery旋转rotate插件,支持Internet Explorer 6.0+ .Firefox 2.0 .Safari 3 .O ...

  9. 【转】打包AAC码流到FLV文件

    AAC编码后数据打包到FLV很简单.1. FLV音频Tag格式                              字节位置    意义0x08,                         ...

  10. hcharts

    折线图 http://www.hcharts.cn/demo/index.php?p=10 饼状图 http://higrid.net/docs/highcharts_cn/#plotOptions- ...