首页 > 代码库 > MVC无刷新上传图片并显示
MVC无刷新上传图片并显示
@{ ViewBag.Title = "Home Page";}<script src=http://www.mamicode.com/"../../Scripts/swfobject.js" type="text/javascript"></script><script src=http://www.mamicode.com/"../../Scripts/jquery.uploadify.v2.1.4.js" type="text/javascript"></script><link href=http://www.mamicode.com/"../../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(" <img src=http://www.mamicode.com/" + 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=http://www.mamicode.com/"javascript:$(‘#uploadify‘).uploadifyUpload()">上传</a> <a href=http://www.mamicode.com/"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"; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。