In asp mvc 5, I launch a download with that code:
//jQuery
$(document).on('click', "#download_export", function (e) {
window.location = url_download;
});
//c#
public FileResult GetFile()
{
return File(Encoding.UTF8.GetBytes("dfdfdf dfssdfdfs"),
"text/plain",
"test.txt");
}
It works and trigger a txt file download on client browser.
I want to do same thing by passing file content on argument from controller,
I tried:
$(document).on('click', "#download_export", function (e) {
$.get(url_download,
{
content : 'this is my content'
}
, function (data) {
console.log('works')
});
});
public FileResult GetFile(string content)
{
return File(Encoding.UTF8.GetBytes(content),
"text/plain",
"test.txt");
}
I saw with debugger that Action is reached but it doesn't trigger a download,
Do you have idea how to do it?
public FileResult GetFile(string content)- what is the value of content when you debug?