帮助上传图像使用asp.net MVC3中的ajax jquery [英] Help upload image use ajax jquery in asp.net MVC3
本文介绍了帮助上传图像使用asp.net MVC3中的ajax jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从客户端到服务器加载图像我编写了以下代码。 MVC3:
1.view:
< input id =btnUploadtype =buttonvalue =上传图片/>
- 代码jquery:
I made loads images from client to server I wrote the following code. MVC3:
1.view :
<input id="btnUpload" type="button" value="Upload image" />
- code jquery :
$('#btnUpload').click(function () {
alert('started');
var file = $('#txtfile').image;
$.ajax({
url: '/Manager/InsertProduct1',
type: 'POST',
dataType: 'json',
data:file,
contentType: 'application/json; charset=utf-8',
success: function (data) {
var d = data;
alert(d);
},
error: function (er) {
alert(er);
}
});
});
2.代码控制器:
2. code controller :
<pre lang="Javascript">
<pre lang="c#"> [HttpPost]
public ActionResult InsertProduct1(HttpPostedFileBase file)
{
string fileName = file.FileName;
file.SaveAs(Server.MapPath("~/Content/Images"));
return Json("Complete!");
}
我做的工作失败了,我需要帮忙吗?
I do the job fails, I need help?
推荐答案
(' #btnUpload')。click( function (){
alert(' started');
var file =
('#btnUpload').click(function () { alert('started'); var file =
(' #txtfile')。image;
('#txtfile').image;
.ajax({
url:' / Manager / InsertProduct1',
类型:' POST',
dataType:' json',
data:file,
contentType:' application / json; c harset = utf-8',
成功: function (数据){
var d =数据;
alert(d);
},
错误: function (呃){
alert(呃);
}
});
});
.ajax({ url: '/Manager/InsertProduct1', type: 'POST', dataType: 'json', data:file, contentType: 'application/json; charset=utf-8', success: function (data) { var d = data; alert(d); }, error: function (er) { alert(er); } }); });
2.代码控制器:
2. code controller :
<pre lang="Javascript">
<pre lang="c#"> [HttpPost]
public ActionResult InsertProduct1(HttpPostedFileBase file)
{
string fileName = file.FileName;
file.SaveAs(Server.MapPath("~/Content/Images"));
return Json("Complete!");
}
我的工作失败,我需要帮助吗?
I do the job fails, I need help?
这篇关于帮助上传图像使用asp.net MVC3中的ajax jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文