c# - how to Get input type file value from bootstrap model in mvc 5 controller using jquery ajax -
this question has answer here:
- file upload using mvc 4 ajax 3 answers
- jquery ajax upload file in asp.net mvc 4 answers
i'm trying input type file value in mvc 5 c# controller unable value. i'm using bootstrap model , jquery ajax task. , dont use form submit this. following code.
bootstrap model code :
<div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4>mark chargeback</h4> </div> <div class="modal-body" align="center"> <div> <input type="file" id="fdocs" class="form-control" style="margin-top: 5px;"/> <input type="submit" id="btngetdocs" class="btn btn-success" value="submit" style="margin-top: 5px;" /> </div> </div> </div>
jquery ajax code :
$('#btngetdocs').click(function () { var docs = $('#fdocs').val(); //alert(docs); $.ajax({ type: "post", url: "../cs/getdocs", data: '{checkimg:"' + docs + '"}', mimetype: "multipart/form-data", contenttype: 'application/json', datatype: "json", success: function (data) { alert(data); $('#mymodal').modal('hide'); }, error: function () { alert(data); } }); });
mvc controller code :
[httppost] public actionresult getdocs(httppostedfilebase checkimg) { try { int result = docs(checkimg); if (result > 0) { return json("docs upload successfully."); } else { return json("please try again."); } } catch (exception ex) { return json(ex.tostring()); } }
so please rid me out problem.
wiki
Comments
Post a Comment