javascript - Partial View on Submit using Ajax call -
here jquery code:
<script type="text/javascript"> $("#submitfileform").submit(function () { $.ajax({ type: 'post', contenttype: 'application/html;charset=utf-8', datatype:'html', success:function (result) { $('#tablepartialview').html(result); }, error:function (xhr, status) { alert(status); } }) }); </script>
and here html.beginform,
@using (html.beginform("propertycolumnmap", "importfile", formmethod.post, new { enctype = "multipart/form-data", @class = "form single-col",id="submitfileform"})) { <input type="file" name="uploadfile" id="uploadfile" value=""/> <select id="assetlist" name="assetlist"> <option>...</option></select> <input class="btn btn-primary" type="submit" value="submit" id="submitfile"/> } <div id="tablepartialview"> </div>
what happens is, on submit, partial view of same page 'index' in div-'tablepartialview', instead of page 'propertycolumnmap', want. after ajax call done,it redirects action 'propertycolumnmap', , view propertycolumnmap.
public actionresult propertycolumnmap(formcollection f, httppostedfilebase uploadfile) { string fileid = import(uploadfile); var excel = new excelqueryfactory(session[fileid].tostring()); excel.databaseengine = databaseengine.ace; var worksheetname = excel.getworksheetnames().last(); var assetname = f["assetlist"].tostring(); mapping(assetname, worksheetname, fileid); return partialview("propertycolumnmap"); }
if possible please include following js project
http://malsup.github.com/jquery.form.js
then can use
$("#submitfileform").ajaxsubmit({ type: 'post', success:function (result) { $('#tablepartialview').html(result); }, error:function (xhr, status) { alert(status); } });
Comments
Post a Comment