ajax - How to send file upload path with normal data to controller in jquery -
i want send file upload image path normal data controller in jquery ajax call . when send normal data works properly. when send image path works when send both in 1 time doesn't work. creates issue sometime ajax call doesn't work or sometime value shows null in controller.
i found many things on net not find exact solution. found solutions like.... missing " enctype" & way getting file upload path & many others.
this js file coding. working , getting complete image path in controller.
var data = new formdata(); var files = $("#btnuploadfile").get(0).files; if (files.length > 0) { data.append("helpsectionimages", files[0]); } $.ajax ({ type: 'post', url: '/login/submituserprofile', processdata: false, contenttype: false, data: data, success: function (result) { }, error: function (result) { } }); controller [httppost] public void submituserprofile() { request.files["helpsectionimages"]; //getting image path }
simple view - use @using(html.beginform.......enctype = "multipart/form-data" , controls
but want send 1 parameter image path...
var userdetail = {}; userdetail.experience = experience; userdetail.pricetype = pricetype; userdetail.services = services;
now, want controller should image path userdetail information specified above.
finally, got solution of question. now, can send image path normal data controller in jquery.
js coding
var userprofile = {}; var userdetail = {}; var hiduserid = $('#hiduserid').val(); var username = $('#txtusername').val(); var experience = $('#txtexperience').val(); var pricetype = $('#txtpricetype').val(); userprofile.hiduserid = hiduserid; userprofile.username = username; userdetail.experience = experience; userdetail.pricetype = pricetype; var userprofilejson = json.stringify(userprofile); var userdetailjson = json.stringify(userdetail); var data = new formdata(); var files = $("#btnuploadfile").get(0).files; if (files.length > 0) { data.append("useruploadedimage", files[0]); data.append("userprofilejson", userprofilejson); data.append("userdetailjson", userdetailjson); } $.ajax({ type: 'post', url: '/login/submituserprofile', processdata: false, contenttype: false, data: data, success: function (result) { }, error: function (result) { } });
controller
[httppost] public string submituserprofile() { try { string userprofilejson = request.form["userprofilejson"]; string userdetailjson = request.form["userdetailjson"]; httppostedfilebase userimage = request.files["useruploadedimage"]; } }
Comments
Post a Comment