'Getting the file return value from controller to ajax/javascript
I am trying to get this returned value from my controller.
Controller:
public ActionResult TestView(string StudentID, string SQNC)
{
string query = "exec sp_someStoredProcedure '" + StudentID + "','" + SQNC + "' ";
string dataStr = GlobalFunction.DataTableToJSON(GlobalFunction.TableFromMSSQL(CampusConnect, query));
dynamic data = JsonConvert.DeserializeObject(dataStr);
byte[] file = data[0].ImgVarbinary;
return File(file, System.Net.Mime.MediaTypeNames.Application.Octet, (string)data[0].FileName);
}
My Script (on button click)
const test = (studid, sqncno) => {
$.ajax({
type: "POST",
dataType: "json",
url: "/ViewUpload/TestView",
data: {
'StudentID': studid,
'SQNC': sqncno,
},
success: function (result) {
console.log(result);
}
});
}
When I running the program, it did not get the return value in success function.
My goal is to get this file value and convert it into base64 string in javascript so I can make it viewable to front-end.
As you can see on the controller, I'm getting the Varbinary string of the file from the database. I tried converting it directly to SQL into base64 string but for some reason It doesn't work (my previous question I made) so I'm trying this approach of getting the file and converting it to base64 into javascript instead.
Thanks for answer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
