Front-end js code
var reader = new FileReader();
reader.readAsArrayBuffer(file); //excel
reader.onload = function () {
//alert("load");
var blob = new Blob([reader.result]);
//
var fd = new FormData();
fd.append("data", blob);
fd.append("filename", file.name);
var aa=fd.get("data"); ///
var xhr = new XMLHttpRequest();
xhr.open("post",
"../UploadExcel",
true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var data = eval("(" + xhr.responseText + ")");
console.info(data);
if (data.success) {
//
var imgName = data.msg;
alert(imgName);
} else {
alert(data.msg);
}
}
}
//
xhr.send(fd);
}
background c-sharp does not use any framework, the most basic controller
[HttpPost]
public string UploadExcel()
{
HttpRequestBase req = Request;
string newname = Request.Form["filename"];
Request.Form["data"]; //stringRequest.Formkey
return null;
}