惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
I
InfoQ
The Register - Security
The Register - Security
L
LangChain Blog
H
Help Net Security
The GitHub Blog
The GitHub Blog
S
Schneier on Security
博客园 - 【当耐特】
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
The Cloudflare Blog
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
雷峰网
雷峰网
N
Netflix TechBlog - Medium
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - 聂微东
PCI Perspectives
PCI Perspectives
Last Week in AI
Last Week in AI
A
Arctic Wolf
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
S
Secure Thoughts
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
SecWiki News
SecWiki News
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
Schneier on Security
Schneier on Security
P
Proofpoint News Feed
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AI
AI
Engineering at Meta
Engineering at Meta

博客园 - liang--liang

项目管理--风险管理 设置全局theme及读取theme方法 项目经理面试题 项目团队发展经历的几个阶段及其特点 软件开发模式简介 通过DataTable 返回Json格式,用于绑定Easyui tree 把DataTable 转换成Json格式,适用于EasyUI 绑定DataGrid c# 把数据表DataTable 导出到Excel 解决document.body.clientWidth 或 document.body.clientHeight 为0的问题 jquery Uploadify 在MVC3中的应用上传 IO Error 解决 MVC下载文件方式 ORACLE中一个字符占多少字节? 软件开发:需求分析的20条法则(转) PowerDesigner PDM 生成SQL脚本 去除双引号方法 PowerDesigner 物理数据模型(PDM) 说明 常见Oracle HINT的用法 Oracle 分区表 总结 《XML实用大全》二 《XML实用大全》一
基于jquery的上传插件Uploadify 3.1.1在MVC3中的使用
liang--liang · 2012-10-14 · via 博客园 - liang--liang

Uploadify是JQuery的一个文件上传插件,实现的效果非常不错,目前已经更新到Version3.1.1,官方提供的实例是php版本的,本文将介绍Uploadify在MVC3中的使用,您可以点击以下链接,去官网查看文档,下载Uploadify插件。

下载Uploadify插件,然后按照以下步骤,在MVC3中应用Uploadify3.1.1插件的上传功能吧。

1.创建MVC3工程,本例命名为UploadifyTest

2.把解压后的Uploadify-v3.1文件夹Copy到工程中的Scripts文件夹下。如下图

以上步骤做完以后,开始写代码了。

.cshtml文件中的代码如下:

复制代码

<link href="/Scripts/uploadify-v3.1/uploadify.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript" src="/Scripts/uploadify-v3.1/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript">
    $(function () {
        $('#upload').uploadify({
            'formData': { 'folder': 'd:\\' },
            'buttonText': '选择文件',
            'buttonClass': 'browser',
            'removeCompleted': false,
            'swf': '/Scripts/uploadify-v3.1/uploadify.swf',
            'uploader': '/Home/Upload'

        });
    });
</script>
<head>
    <style type="text/css">
        .browser
        {
            color:White;
        }
    </style>
</head>
<input type="file" name="upload" id="upload" />

复制代码

cs文件代码如下:

复制代码

public class HomeController : Controller {
        public ActionResult Index() {
            return View();
        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ContentResult Upload(HttpPostedFileBase FileData, string folder) {
            string filename = "";
            if (null != FileData) {
                try {
                    filename = Path.GetFileName(FileData.FileName);//获得文件名
                    string fullPathname = Path.Combine(folder, filename);
                    saveFile(FileData, folder, filename);
                } catch (Exception ex) {
                    filename = ex.ToString();
                }
            }
            return Content(filename);
        }

        [NonAction]
        private bool saveFile(HttpPostedFileBase postedFile, string filepath, string saveName) {
            bool result = false;
            if (!Directory.Exists(filepath)) {
                Directory.CreateDirectory(filepath);
            }
            try {
                postedFile.SaveAs(Path.Combine(filepath, saveName));
                result = true;
            } catch (Exception e) {
                throw new ApplicationException(e.Message);
            }
            return result;
        }
    }

复制代码

上传效果如下:

用到的上传参数说明

'formData': 向后台传递的参数

'buttonText': 上传按钮上显示的文字

'buttonClass': 给上传按钮添加的

class'removeCompleted': 表示在上传完成后是否删除队列中的对应元素。默认是True,即上传完成后就看不到上传文件进度条了。
'swf': swf文件路径
'uploader': 调用后台操作的方法

转自 http://www.cnblogs.com/greenteaone/archive/2012/06/14/2549112.html