MVC无刷新上传图片并显示

@{
    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";
            }  
           
        }

转载于:https://www.cnblogs.com/sky-net/p/3853391.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值