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

MVC上传图片

时间:2015-07-17 09:37:13      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

 

 

<td rowspan="8"> 图片为:
<input type="hidden" name="img_url" id="img_url" value="@Model.img_url"/>
<img id="img_head1" style="height:200px; width:300px; @(Model.img_url == "" ? "display:none;" : "")" src="@(AppSettingGetValue.getFileServices() + "platformContent/TuWen/" + Model.img_url)"/><br />
<input type="file" name="fileImgUrl" id="fileToUpload1" multiple="multiple" onchange="fileSelected(1);" />
<a id="uploadFile1" style="display: none" href="#" class="easyui-linkbutton" data-options="iconCls:‘icon-save‘" onclick="uploadFile(1)">上传</a>
</td>

 

 

JQuery控制图片上传

 

function fileSelected(itype) {
$("#uploadFile" + itype).show();
}

var uploadtype = 0;
function uploadFile(itype) {
uploadtype = itype;
var fd = new FormData();
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", uploadComplete, false);
fd.append("fileToUpload", document.getElementById(‘fileToUpload‘ + itype).files[0]);
if (itype == 0) fd.append("UpLoadAdress", "platformContent\\TuWen\\");
else fd.append("UpLoadAdress", "platformContent\\TuWen\\");
xhr.open("POST", "@Url.Content("~/Common/UploadFile")");
xhr.send(fd);
}

function uploadComplete(evt) {

/* 服务器返回数据 */
var message = evt.target.responseText;
if (uploadtype == 0) {
$("#img_head").show();
$("#img_head").attr("src", "@(BBAdmin.Common.AppSettingGetValue.getFileServices())platformContent/TuWen/" + message);

if ($("#fileToUpload" + uploadtype).val() == "") {
$.message.alert("提示", "二维码上传成功!", "info");
}
else {
$("#fileToUpload" + uploadtype).val("");
}
}
if (uploadtype == 1) {
$("#img_head1").show();
$("#img_url").val(message);
$("#img_head1").attr("src", "@(BBAdmin.Common.AppSettingGetValue.getFileServices())platformContent/TuWen/" + message);
//$("#img_url").val($("#img_head1").attr("src"));

if ($("#fileToUpload1" + uploadtype).val() == "") {
$.messager.alert("提示", "头像上传成功!", "info");
}
else {
$("#fileToUpload1" + uploadtype).val("");
}
}
}

MVC上传图片

标签:

原文地址:http://www.cnblogs.com/zxk3113/p/4653493.html

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