码迷,mamicode.com
首页 > Web开发 > 详细

MVC无刷新上传图片并显示

时间:2014-07-18 18:18:34      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:style   blog   java   color   width   io   

@{
    ViewBag.Title = "Home Page";
}
<script src="../../Scripts/swfobject.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
<link href="../../Content/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#uploadify").uploadify({
            uploader: /content/uploadify.swf,
            script: /Home/Upload,
            cancelImg: /content/cancel.png,
            folder: UploadFile,
            queueID: fileQueue,
            auto: false,
            multi: true,
            onComplete: function (event, ID, fileObj, response, data) {

                $(#div_img).after("&nbsp;&nbsp;&nbsp;<img src=" + response + " alt=‘‘ height=‘100‘ width=‘100‘ />")

            }
        });
    });  
</script>
<div id="div_img">
</div>
<div>
    <div id="fileQueue" style="text-align: center">
    </div>
    <input type="file" name="uploadify" id="uploadify" />
    <p>
        <a href="javascript:$(‘#uploadify‘).uploadifyUpload()">上传</a>&nbsp; <a href="javascript:$(‘#uploadify‘).uploadifyClearQueue()">
            取消上传</a>
    </p>
</div>
public string Upload(FormContext from)
        {
            var file = Request.Files["Filedata"];
            string uploadPath = Server.MapPath("~/images/");
            string url = "/images/" + file.FileName;
            if (file != null)
            {                
                file.SaveAs(uploadPath + file.FileName);
             
                return url;//返回保存的地址
            }
            else
            {
                return "0";
            }  
           
        }

MVC无刷新上传图片并显示,布布扣,bubuko.com

MVC无刷新上传图片并显示

标签:style   blog   java   color   width   io   

原文地址:http://www.cnblogs.com/sky-net/p/3853391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!