This article mainly introduces Jquery asynchronous upload of file code examples. The example code is introduced in this article in detail, which has certain reference value for everyone's learning or work. Friends who need it can refer to it.
1, view code
<form role="form"> <div class="form-group"> <label for="keyinput">Select a file:</label> <input type="file" name="upfile" /> </div> <div class="form-group"> <input class="btn btn-minw btn-danger" type="button" onclick="importExp()" value="ajax import" /> </div> </form>
function importExp() { var formData = new FormData(); ("file", ("upfile").files[0]); $.ajax({ type: 'POST', url: '/s/Import', data: formData, cache: false, contentType: false, processData: false, success: function (data) { (); // Clear input file native js var file = ("upfile"); // for IE, Opera, Safari, Chrome if () { = ; } else { // FF (including 3.5) = ""; } } }); }
2. Controller code
public JsonResult ImportExecl() { bool isOk = false; var file = [0]; if (file == null || <= 0) { return Json(new { IsOk = isOk, msg = "Please upload excel file" }); } if (!new List<string>() { ".xls" }.Contains(())) { return Json(new { IsOk = isOk, msg = "Please upload an excel file in the format .xls" }); } var a = ; }
In summary, you can get the file stream and then operate the file stream
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.