我曾在Web应用程序中导出数据在网格中,我想在C#,Javascript中使用“另存为”对话框保存它们。
function openDialog() {
var input = $(document.createElement('input'));
input.attr("type", "file")
input.trigger('click');
return false;
}
测试
答案 0 :(得分:0)
[HttpGet]
public async Task<HttpResponseMessage> Get(string fileHash)
{
//read file
byte[] fileData = await _deviceFileApiService.GetFileData(fileHash);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(fileData)
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = fileResource.FileName
};
return response;
}
UI上的
<a href="<you url to action here>/get">save as</a>
当用户点击链接时,将出现另存为对话框。