且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

帮助上传图像使用asp.net MVC3中的ajax jquery

更新时间:2021-09-01 08:09:43

' #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?